C++/CLI Tutorial – How to monitor managed object in C++ program

Java Việt Nam

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:

Happy coding!!

View original post

Advertisements

About Khuram Ali

Programming... Programming and Programming...!!!

Posted on May 2, 2013, in C++. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: