On 04/18/2011 10:31 AM, %u 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;

No, you don't need to manually delete pixels, but also not the pointer.

By the way, structs are constructed on the stack; only by using 'new' will it be on the heap, but you often don't need that. Conversely, if you want truely referenced and heap-allocated objects, you may want to use class instead of struct.

A common exception may be for data structures made of possibly numerous "pointed" objects, such as linked lists or trees of struct nodes. There, you may want manually pointed struct objects.

Denis
--
_________________
vita es estrany
spir.wikidot.com

Reply via email to