We have some STA-affine objects so we hand out winrt::agile_ref's to callers so that they can safely communicate with them from other threads. I am adding some cleanup code and I need to be able to cast these to IClosable and close them from a random MTA thread. The tricky part is that I need that cleanup code to hold weak references so I don't create a reference cycle and guarantee leaking of these objects.
cppwinrt has both weak_ref and agile_ref but they cannot be combined. This feature request is to add an agile_weak_ref struct that supports this.
Reproducible example
No response
Expected behavior
No response
Actual behavior
No response
Additional comments
@DefaultRyan had a code suggestion via email that I'm preserving here:
Version
2.0.230706.1
Summary
We have some STA-affine objects so we hand out winrt::agile_ref's to callers so that they can safely communicate with them from other threads. I am adding some cleanup code and I need to be able to cast these to IClosable and close them from a random MTA thread. The tricky part is that I need that cleanup code to hold weak references so I don't create a reference cycle and guarantee leaking of these objects.
cppwinrt has both
weak_ref
andagile_ref
but they cannot be combined. This feature request is to add anagile_weak_ref
struct that supports this.Reproducible example
No response
Expected behavior
No response
Actual behavior
No response
Additional comments
@DefaultRyan had a code suggestion via email that I'm preserving here: