Linus with some good observations on garbage collection

Iain Buclaw ibuclaw at ubuntu.com
Fri Apr 22 15:21:07 PDT 2011


== Quote from bearophile (bearophileHUGS at lycos.com)'s article
> Timon Gehr:
> > But, as pointed out by Linus, the prime performance problem is _not_ the GC, but
> > the mindset that comes with it. Most programmers that "grew up" in a managed
> > environment tend to use very many "new" keywords all over their code, instead of
> > allocating large chunks of memory at once. (Java/C#/etc encourage you to do this.)
> In C99 (and Ada) you avoid the allocation of some dynamic arrays with new thanks
to variable length arrays.

Variable length arrays are just sugary syntax for a call to alloca.

> > This is also the reason I think it is a bad idea to deprecate D's 'delete'.
> D used to have scoped class instances, scoped classes, and delete, their
replacements are not good enough yet. In CommonLisp you have hints for the GC,
they are safe and they help you help speedup the work of the GC. Such hints
probably need to be integrated with the type system, so they may need to be
built-ins as scope/delete were. I am not seeing enough discussion about this.
> Bye,
> bearophile


I've always felt that Vala's system is better thought out, which is incidentally
based on a reference counting system. This makes destructors in Vala deterministic
and can be used to implement an RAII pattern for resource management.
To get around the common pitfalls of reference counting systems, they introduce
two keywords which alter the relationship between the allocated object and the GC,
'weak' and 'unowned'.

Rather than bore you with the gritty details here, see link:
http://live.gnome.org/Vala/ReferenceHandling


More information about the Digitalmars-d mailing list