Freeing of memory (garbage collection)

BCS ao at pathlink.com
Mon Dec 8 21:02:37 PST 2008


Reply to Dan,

> A couple of questions:
> 
> 1: Even though D has an automatic garbage collector, is one still
> allowed to free the memory of a malloced array manually (using free ()
> ), to avoid pauses in the program?
> 

Yes, in fact if you malloc memory you MUST free it. Only stuff like dynamic 
arrays, AAs and new'ed stuff gets cleaned up by the GC.

> 2: One justification on the website for using automatic garbage
> collection is how "allocated memory will only be freed if system RAM
> is tight". But surely that's silly, since one may want *lots* of
> memory free for a completely different application (merely memory
> being 'tight' before freeing may not be good enough - one may want D
> to free memory sooner).
> 

With virtual memory and swap space, this (almost) no longer matters. If you 
aren't using memory sooner or later it's not using your RAM but just sitting 
on the disk.




More information about the Digitalmars-d-learn mailing list