Compile without GC support

Stewart Gordon smjg_1998 at yahoo.com
Sat Dec 16 12:27:29 PST 2006


Daniel Keep wrote:
<snip>
> 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.

There are a number of ways to trigger allocation of memory on the heap:
- using associative arrays
- setting .length of an array
- calling .dup on an array
- concatenating arrays with ~ or ~=
- maybe others....

> 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.)

It does seem to've changed since I last looked.

<snip>
> 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.

I'd think it would make an effort to clean up so that it can reuse 
existing memory rather than claiming more and more from the OS.

Stewart.


More information about the Digitalmars-d-learn mailing list