Deallocate array?

Steven Schveighoffer schveiguy at yahoo.com
Wed May 8 06:46:23 PDT 2013


On Wed, 08 May 2013 08:28:50 -0400, Matic Kukovec  
<matic.kukovec at pametnidom.si> wrote:


> Thanks for the explanation Steve.
>
> Can you please give me a correct example of:
> - creating a dynamic string array

auto arr = new char[N];

N can be a runtime value.

> - looping over it and adding values

Not sure what you mean here.

> - discarding/releasing the array from memory

correct:

arr = null; // GC should collect

dangerous:

GC.free(arr.ptr);

Due to conservative GC, you may need to explicitly free memory for  
practical reasons (e.g. if GC doesn't seem to collect the data you  
release).

This problem is MUCH less prevalent on 64-bit, since the memory space is  
quite sparse.

-Steve


More information about the Digitalmars-d-learn mailing list