I need a way to track instances of various classes, without these classes not knowing that they are being tracked. Essentially, I have a factory class that creates instances and passes them to another thread. After this thread completes and unloads the instance, I need to get a notification about this so that I can perform reference counting and exit my factory class when all instances have disappeared.
The problem is that I cannot change any of the classes that I will load, because I do not control their source code.
Keeping track of the instances I create is simple, I can just put them in some kind of collection when I create them. Tracking their destruction is causing me problems. If I could change the source code, I would add an event to each class, and when I create an instance, I hooked on this event and used it as my notification. But I canβt do it.
So, the question is: is there a hidden way to control an instance of an object and detect when it is destroyed?
Tim long
source share