Re: Garbage Collection
Posted: Jan 3, 2006 2:54 PM
> and there are good garbage collectors "out there".
Hmm... maybe, but I think GC is such a kind of feature that it better have language support. Like exceptions.
> > Why is the new proposal needed? Or is it a requirement
> > that a standards-conforming compiler have a garbage
> > collecting implementation available on demand?
> To clarify "optional"
First of all, it needs to be decided whether the type definitions should be strictly bound to their memory management issues, or they can be separate, while the storage is used directly by using appropriate, say, syntax.
So far the garbage collectors use the second method because they simply don't have another choice.
And I disagree that you can just "use garbage-collection for any type". The ability of an object to be garbage-collected or not should be a treat of its type.
This is moreover important that the manual memory-managed objects are simultaneously guaranteed to be freed in strictly specified places. Removing an object by GC does not occur in specified moment. This, for example, implies that the GC'd objects must be trivially-destructible because many "typical" destructors try to do something in other objects.
If it is strictly stated that garbage-collected and non-garbage-collected are separate types, then the garbage collector can be optional and will not make additional costs for those, who are not interrested with it.
Others, on the other hand, point that the environment should be either fully garbage-collected or not. With such statements, the GC is simpler to be implemented. However I can't imagine, how SUCH C++ would compose with its existing libraries.
> To exactly define what it means for an object to be alive
When accessible from other alive objects ;). Of course, this is a complicated thing, but I think GCs today are mature enough and some reasonable method can be developed for C++.
> To give the programmer a way of knowing whether GC is
Is there a way to inform a user that exception throwing is happening in any other way than by caching the exception?
> To define what "delete p;" means whan a garbage collector
> is running
Nothing. Unless 'p' points for an object, which is of a garbage-collected type. This would be prevented at compile time, if GC had a language support.
> That said, please note that GC isn't a panacea and isn't
> for every program.
I saw only few situations, when GC would be suitable. A lot of examples from Java's uses for GC (for example, to return a large object by reference) can be done in C++ without GC (this one, for example, with auto_ptr).