C++/CLI Tutorial – How to monitor managed object in C++ program
Almost C++ programmer want to manage all object they created. But when they use gcnew in C++/CLI to create objects, it seems they were not able to control these objects and that makes them feel uncomfortable.
We can only set these object to nullptr and cannot delete it by calling delete, this is responsibility of GC. We can call GC.Collect to collect all objects that are no longer reference to.
In .NET, we have WeakReference class which allows us to monitor managed object to ensure that when we call GC.Collect, whether these object was deleted or not.
And here is source code to illustrate for what I said: