Thomas2054

I am used to the C++ requirement of using

delete [ ] array_pointer;

to free memory.

If I have a CLI array like

pString_progString = gcnew array<System:Tongue Tiedtring ^>(7);

How do I delete it I have read that I should not use the "delete [ ]" form, but I do not know what to use.

The help system for "array" makes no mention of this.

I am new to the CLI constructs and thus may be missing something basic.

Thanks.

Thomas



Re: Visual C++ Language Deleting a CLI array

nobugz

You don't. The garbage collector will delete it for you. You are missing something basic, read up on the .NET garbage collector. It is important.





Re: Visual C++ Language Deleting a CLI array

Thomas2054

nobugz,

Thanks for the reply. I looked at the material on garbage collector and it does make reference to deleting a tracking handle in order for the object's destructor to be run.

I can understand not using delete on an object that has no destructor, or at least no destructor written by me. But what of an object with an destructor in which there is important stuff to run

If I have an CLI array of with objects that have a destructor how do I invoke it

Thanks.

Thomas





Re: Visual C++ Language Deleting a CLI array

nobugz

In the new C++/CLI syntax, the destructor for a managed class has an entirely new meaning. It is invoked when you call Dispose() or exit a block where the class instance is declared as a local variable (no hat). The finalizer (!ClassName) is invoked by the garbage collector, whenever it feels ready to do so. You should avoid using it.

I can't really think of a good reason you'd need a destructor for a CLI array. Both the array and its elements are automatically "deleted" by the garbage collector.





Re: Visual C++ Language Deleting a CLI array

Thomas2054

Thanks nobugz for taking the time. You have gotten me off BDC by showing me were to look for more information and the fact that the destructor now serves a different purpose than in C++ originally.

Thomas