How to delete multidimesional array in Visual C++ .Net 2008?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Abhijitit
    New Member
    • Nov 2008
    • 4

    How to delete multidimesional array in Visual C++ .Net 2008?

    Hello,

    I have Class name as MyClass and created multidimesional array of object.
    Example is given below.

    // clr_array.cpp
    // compile with: /clr
    ref class MyClass {};
    int main() {
    array<MyClass ^> ^ MyArray = gcnew array<MyClass ^>(100);
    }


    I have problem, how to delete this array of objects.?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Is this C++ or some MS-ism?

    kind regards,

    Jos

    Comment

    • oler1s
      Recognized Expert Contributor
      • Aug 2007
      • 671

      #3
      It's C++/CLI, the modified version of C++ for the .NET platform. Good luck getting good help for it.

      Do you need to delete the array of objects? I imagine they get garbage collected.

      Comment

      • vmpstr
        New Member
        • Nov 2008
        • 63

        #4
        This is MS-ism. Apparently, ^ is to signify a handle, which acts basically like a pointer, but is garbage collected (hence gcnew instead of new: gc stands for garbage collected).

        Given that it is garbage collected, it will be deleted for you once there are no more preferences to that address... hopefully.

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          If you really feel the need to you can use delete to delete objects allocated with gcnew. However as has already been pointed out gcnew returns a handle that the garbage collect monitors and when there are not more references to that handle the data is automatically deleted (garbage collected).

          Comment

          Working...