Compile without GC support
Daniel Keep
daniel.keep+lists at gmail.com
Mon Dec 11 21:02:56 PST 2006
Heinz wrote:
> Thanks Daniel for your answer.
> OK, the GC get always linked, so i'll get extra bytes in my files but, does this
> mean that the GC is active (run) when i open my application or the GC is just a
> simple bunch of functions that are never called?
>
> Heinz
The GC is "run" in the sense that it is initialised when the application
starts up.
However, what you have to understand is that the GC will not run a
collection cycle UNLESS you attempt to 'new' some memory, and you've run
out. If you, for example, use C's malloc and free, then the GC won't
ever be triggered.
(An exception to this is that when you quit, the GC runs a collection to
clean up... I think.)
One other thing to keep in mind is that you can override the use of the
GC on a per-class basis by overriding a class' 'new' member. Lemme see
if I can find the doc for it...
http://digitalmars.com/d/class.html#allocators
So, summary:
1. With stock DMD, the GC is always linked in.
2. The GC is always initialised on program startup.
3. The GC is used (by default) for the 'new' operator.
4. You can use a different allocator for 'new' on a per-class basis.
5. You can use any allocation scheme you like so long as you manually
call it.
6. A collection is only run if you attempt to 'new' some memory, and
there isn't enough free memory.
Hope that covers everything.
-- Daniel
More information about the Digitalmars-d-learn
mailing list