Please help with GC exception!
Steven Schveighoffer
schveiguy at yahoo.com
Wed May 9 10:03:21 PDT 2012
On Wed, 09 May 2012 12:52:43 -0400, Gor Gyolchanyan
<gor.f.gyolchanyan at gmail.com> wrote:
> I got your point. Thanks for the reply!
> Wouldn't it make more sense for GC to ignore second deallocation?
The memory may have already been reallocated elsewhere!
> If this was the case, data, which is know to become garbage would be
> deallocated right away.
> On the other hand, I might as well use std.c.stdlib.realloc for these
> cases.
Do not call C's realloc on GC allocated memory.
The best option is to avoid the GC whatsoever for memory that you want to
manage that tightly. Use c's malloc and free, which can be called from
the dtor, no problem. If the block has pointers to GC memory, remember to
addRoot it (and removeRoot it in destructor).
-Steve
More information about the Digitalmars-d
mailing list