tags:

views:

4614

answers:

3

I stumbled across this code and am too proud to go and ask the author what it means.

Hashtable^ tempHash = gcnew Hashtable(iterators_);

IDictionaryEnumerator^ enumerator = tempHash->GetEnumerator();

What is gcnew and how important is it to use that instead of simply new? (I'm also stumped by the caret; I asked about that over here.)

+6  A: 

gcnew is for .NET reference objects; objects created with gcnew are automatically garbage-collected; it is important to use gcnew with CLR types

Steven A. Lowe
@[Chris Jester-Young]: Thanks Chris, that's good to know how to fix the MS links
Steven A. Lowe
+4  A: 

gcnew is an operator, just like the new operator, except that you don't have to delete anything created with it. It's garbase collected. You use gcnew for creating .Net managed types, and new for creating unmanaged types.

Joel Coehoorn
upvoted (not that you need the points) because we posted the same answer at the same time
Steven A. Lowe
+1  A: 

You can read about some of the C++/CLI features here:

http://en.wikipedia.org/wiki/C%2B%2B/CLI

Mark Ingram