Search code examples
.netc++-cli

What is gcnew?


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.)


Solution

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