(^)Handle and ref new/gcnew[C++/CLI]

I should say first that I am new to win programming so please excuse me.
Why must a handle declared with ^ operator must be used with ref new/gcnew? I read the documentation on MSDN and it says the handle obj will be automatically deleted when out of scope, so why would not new do the job?
closed account (z05DSL3A)
first, C++ != C++/CLI.

A handle (^) is from C++/CLI as is gcnew. A handle is somewhere between a point and a reference in C++. gcnew creates objects on the managed heap and asignes it to the handle. When the handle goes out of scope the reference count on the object it is assigned to is decremented and the handle is destroyed. If the object of the managed heap has a zero reference count then it can be removed by the garbage collector.

C++ new creates an object on the unmanaged heap and returns a pointer for assignment. If the returned address is assigned to a vanilla pointer and that pointer goes out of scope, the pointer is destroyed and the object is lost on the heap (leaked).

The main point I'm trying to get across id that mixing C++ and C++/CLI is not the best thing to do if you don't know what you are doing. If you want to learn C++/CLI learn it from the ground up and don't be tempted to mix it with C++ in an ad hoc basis.
Topic archived. No new replies allowed.