Re: Garbage Collection - The Trash Begins To Pile Up
Peter Dimov wrote:
Thant Tessman wrote:
Mirek Fidler wrote:
Ownership is always clear, people are just too much used to putting
pointers and "new" everywhere to see it. [...]
Nonsense. As I described elsewhere, the use of pointers in C++ is
unavoidable when an object is serving as an encapsulation of state. And
any but the simplest C++ programming tasks will inevitably require
objects to be instantiated in one place and deleted in another in a
Many complex C++ programming projects do not need to garbage collect at
all (and here I include shared_ptr as a poor man's collector). In these
scenarios, the primary uses of shared_ptr are to break dependencies and
to keep (possibly polymorphic) objects in containers while retaining
the option to keep a weak_ptr or to temporarily extend their lifetime
to the end of the current scope. Sometimes to tie an object's lifetime
to external events.
Basically, people who emulate GC with shared_ptr think that GC will be
better, and they are right. People who use shared_ptr for other
purposes think that GC will not help them, and they are right, too.
And what about those of us who do both:-). I have any number of
classes that more or less use the same strategy as
boost::shared_ptr (a number of classes, because I still have to
support Sun CC 4.2, which very definitly limits genericity).
One of them (my RefCntPtr) is usually used as an ersatz for
garbage collection, but the others aren't, at all.
I certainly think it worth keeping both options open. Along
with auto_ptr (very, very useful in multithreaded code),
unique_ptr, scoped_ptr, and any number of others.
James Kanze (Gabi Software) email: email@example.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]