-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling the references of COM objects #2472
Comments
Unloading is generally very unreliable, so I usually recommend not implementing |
How can I track dropping of objects? Can you kindly provide an example please? |
You can implement the |
Thanks! |
A while back I found myself confronted with the same questions, so here's a bit more information: A COM server only needs to track the actual object count to implement Since a COM server also implements the class factory, which every external instantiation request necessarily has to go through, it is now in control over both the start and the end of a COM object's life. This allows to, in theory, implement the counter representing the I said "in theory", since (as I discovered) it is very fragile in practice. While not impossible to get right, it's very challenging to keep it that way. All it takes is a single interface method that instantiates a COM object, without updating the object counter (say, a I ultimately settled for always returning |
Thanks a lot, @tim-weis! ❤️ |
Unloading is generally very unreliable, so we don't take the hassle of keep tracking when the DLL is ready to be unloaded. microsoft/windows-rs#2472 (comment)
There's nothing that prevents instances from outliving factories. C++/WinRT for example simply keeps track of all outstanding objects, factory or not. |
@kennykerr I realize that that was worded in an unfortunate way. I didn't mean to imply that a live class factory were the indicator for outstanding object references. Indeed, the factory is commonly the first thing to go once a client has obtained their object of interest. What I meant to say is that the class factory implementation is under the (COM server) author's control, and with all object instantiation requests going through it, it is a convenient place to increment the object counter for each successfully serviced request. Hope that makes more sense. |
Yep, best advice is still to avoid exporting |
Currently the reference handling functions(
AddRef()
andRelease()
) are hidden and are implemented by theimplement
macro for custom COM objects, which is a good approach that reference counting is made implicit. But it creates an issue when we need to know the number of references of an object is still alive, currently this is not exposed by any of the APIs. When implementing an inproc COM server, there is a requirement to implement theDllCanUnloadNow()
function to indicate if the DLL is ready to be unloaded. If there are references alive it returnsS_FALSE
otherwiseS_TRUE
.We can somewhat at least keep the track of how many references of the objects are being created. But how do we track the
Release()
of the references? Do you have a solution or workaround in mind?The text was updated successfully, but these errors were encountered: