Garbage collection for Managed Classes in VC++.net

Started by
2 comments, last by boogie woogie 18 years, 8 months ago
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
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.
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.
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.

This topic is closed to new replies.

Advertisement