== Quote from Steven Schveighoffer (schvei...@yahoo.com)'s article
> On Mon, 18 Apr 2011 04:31:26 -0400, %u <lenochw...@gmail.com> wrote:
> > Is it necessary free memory allocated for member of structure, like in
> > C? I
> > suppose not (we have gc). Example:
> >
> > struct BITMAP {
> > (...)
> > ubyte[] pixels;
> > }
> >
> > BITMAP* bitmap = new BITMAP;
> > bitmap.pixels = new ubyte[100*100];
> > (...)
> >
> > // delete bitmap.pixels; //not necessary?
> >
> > delete bitmap;
> It is not necessary, because pixels will be collected by the GC sometime
> in the future.  It will *not* free pixel's data by calling delete on the
> BITMAP pointer.
> Just a note, you may be tempted to use a destructor do effect the above
> (as is done in C++ commonly), but this is a very big mistake.

So what is "correct" way to manage structures like BITMAP? Don't bother with
freeing memory at all?

> And one other note -- delete will eventually be deprecated.  In order to
> free memory, you must use clear and GC.free.
> -Steve

It's pity. I like delete.:)

Reply via email to