• Advertisement
Sign in to follow this  

Garbage collection for Managed Classes in VC++.net

This topic is 4593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Recently I downloaded the VC++.NET 2005 Express Edition (Beta 2) so that I could use it to develop simple 'Managed' applications. Knowing nothing about managed code, I also purchased Microsofts 'Visual C++.NET step by step' book (2003 edition). Unfortunately the syntax for certain features appears to have changed (I know I can still compile with '/CLR:OldSyntax') which has lead to some confusion on my part. Throughout the book managed classes are prefixed _gc I understand why this is and that the new syntax is to prefix it with 'ref' instead. My question is - If I allocate these types of classes using 'new', will garbage collection still take place when they go out of scope, or should I still 'delete' them. I'm a bit confused because if they are deleted automatically then why have a 'gcnew' function? The book appears to say 'new' allocated _gc objects will be swept up. Boogie

Share this post


Link to post
Share on other sites
Advertisement
I thought that garbage collection was more of a java thing and if you use c++ you should always just delete unused objects yourself to avoid leaks and cut back on resources.

Share this post


Link to post
Share on other sites
Quote:
Original post by SKATIN_HARD
I thought that garbage collection was more of a java thing and if you use c++ you should always just delete unused objects yourself to avoid leaks and cut back on resources.


You've obviously never heard of Managed C++...


OP: Reading here gives some examples which use gcnew, with this weird "Managed handle (^) and reference (%) syntax"

More information on gcnew can be gleaned through the MSDN search feature.

I have the feeling that's the prefered syntax, as searching for "_gc" only gets like 8 hits, none of which appear to be related.

Not actually using managed C++ myself, I can't help you much, sorry.

Share this post


Link to post
Share on other sites
Thanks for your comments.

I've found this guide that I will use in conjunction with the book. I imagine a new edition of the book will come out later this year.

Boogie.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement