About RAII and GC...?

Jarrett Billingsley kb3ctd2 at yahoo.com
Mon Jul 30 18:58:38 PDT 2007


"Nick Sabalausky" <a at a.a> wrote in message 
news:f8m0fq$2ogm$1 at digitalmars.com...
> Maybe I'm misunderstanding things, but if you use RAII wherever 
> appropriate, wouldn't that eliminate the need for garbage collection? Is 
> there something I'm missing here?

Go ahead and program your entire program without persisting any state 
outside the program execution stack.  Let us know how it goes ;)

Basically RAII only works for local function variables.  If you want the 
lifetime of an object to be controlled by something other than the execution 
time of a function, that's what the GC is for.

Although I wonder how much the GC could be helped by means of a new kind of 
object lifetime control, where the lifetime of one object is controlled by 
the lifetime of another.  Collecting the "parent" object would cause the 
"child" object to be collected, and the child couldn't be collectable until 
the parent object was. 





More information about the Digitalmars-d mailing list