Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2005-06-07 05:31:57


Lorenzo Bettini <bettini_at_[hidden]> writes:

> David Abrahams wrote:
>> Can you deal with deallocation of the whole network at once? It often
>> works to maintain the nodes (C objects) in a container like a deque
>> and let them link to one another with raw pointers.
>> Otherwise you may be in need of a real GC.
>>
>
> I solved the problem in a (probably) not too elegant way: when I know
> that I'm creating objects with mutual dependences say A and B I store
> weak pointers, and I store a shared pointer to A and B into a list. As
> long as the list survives the weak pointers are still valid. When I
> want to deallocate everything, all I have to do is to deallocate the
> list. This worked, and also valgrind says there are no leaks...

The smart pointers may not be buying you much of anything in that
case.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk