Re: Garbage Collection - The Trash Begins To Pile Up
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
non-deterministic way.
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.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]