Skip to content

Conversation

@oldnewthing
Copy link
Member

Originally, factories defaulted to no_weak_ref because there wasn't believed to be any use case for weak references to factories, and the thought was that the weak reference support would be a performance penalty.

In practice, the weak reference support does not have a significant performance impact, so it's okay to leave it on even for factories.

Allowing weak references to factories is important because factories implement the static members of a runtime class, and those members may require taking weak references:

  • Event handlers need weak references so that the event handler doesn't create a circular reference back to the factory.
  • Queueing work to a background thread takes a weak reference so that the work can be abandoned if the factory has been destroyed. (We don't want to extend the lifetime of COM objects beyond the lifetime of COM itself.)

Furthermore, the ability to take a weak reference to a factory is required in order to use event_revoker for static events, since event_revoker requires that the event source support weak references.

Originally, factories defaulted to no_weak_ref because there wasn't
any use case for weak references to factories, and the thought was
that the weak reference support would be a performance penalty.

In practice, the weak reference support does not have a significant
performance impact, so it's okay to leave it on even for factories.

Allowing weak references to factories is important because factories
implement the static members of a runtime class, and those members
may require taking weak references:

* Event handlers need weak references so that the event handler
  doesn't create a circular reference back to the factory.
* Queueing work to a background thread takes a weak reference
  so that the work can be abandoned if the factory has been destroyed.
  (We don't want to extend the lifetime of COM objects beyond the
  lifetime of COM itself.)

Furthermore, the ability to take a weak reference to a factory
is required in order to use event_revoker for static events,
since event_revoker requires that the event source support weak
references.
}

using is_factory = std::disjunction<std::is_same<Windows::Foundation::IActivationFactory, I>...>;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting this public type is a potential breaking change. Do we care?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it matters too much - developers can easily sniff this out themselves - and its not likely to be something a project would depend on, I think.

@oldnewthing oldnewthing requested a review from kennykerr April 2, 2021 17:51
Copy link
Collaborator

@kennykerr kennykerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@kennykerr kennykerr merged commit b52df71 into master Apr 3, 2021
@kennykerr kennykerr deleted the weak-factories branch April 3, 2021 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants