Object Pointer
Jonathan M Davis
jmdavisProg at gmx.com
Wed Jul 18 15:47:05 PDT 2012
On Wednesday, July 18, 2012 20:37:50 Namespace wrote:
> Only for correctness:
> If i allocate memory on the GC Heap in e.g. a struct and don't
> free the memory in the DTor, then the GC free the memory
> automatically?
You don't normally _ever_ free memory from the GC heap. That's the GC's job.
That's what garbage collectors _do_. There are cases where it may be valuable
to explicitly free GC memory for performance reasons, but it's risky and opens
yourself up to the possibility of accessing freed memory and the like. That's
one of the reasons why delete is being deprecated.
So, no, you don't have to free GC allocated memory in a struct's destructor.
The GC takes care of it.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list