Dynamic Array Question

Jonathan M Davis jmdavisProg at gmx.com
Tue Sep 20 18:43:48 PDT 2011


On Tuesday, September 20, 2011 21:48:10 Christophe wrote:
> > To avoid having to change your other code, I'd do this:
> > 
> > wchar[] t = ...;
> > scope(exit) delete t; // add this line to the end of the function (after
> > returning)
> > 
> > There is another way, but it's not as easy:
> > 
> > // put this at the top of file
> > import core.memory;
> > 
> > ...
> > 
> > scope(exit) GC.free(t.ptr);
> 
> does "scope wchar[] t = ...;" work too ?

I'm not sure, but scope as a modifier on local variables like that is going to 
be removed from the language. std.typecons.Scoped is replacing it.

However, unless you're having major memory issues, I really wouldn't worry 
about it. Just let the garbage collector do its thing. It's not the best, but 
it works fine in most cases.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list