|
Boost Users : |
Subject: Re: [Boost-users] memory lost using cyclic pointers (shared_ptr)
From: Nat Linden (nat_at_[hidden])
Date: 2011-09-09 11:10:05
On Fri, Sep 9, 2011 at 4:13 AM, Max Vasin <max.vasin_at_[hidden]> wrote:
> 2011/9/9 Igor R <boost.lists_at_[hidden]>:
>> On of the directions should use weak_ptr.
> The question was what to do if these directions are very hard figure
> out correctly. Conservative GC can be a semi-solution
> leaks will still remain but programming will be much simpler.
One could imagine a scenario in which you define your cross-linked
data structure to the Boost Graph Library as a graph. When it's time
to free your whole structure, you run a graph-traversal algorithm to
identify cycles, then manually reset() specific shared_ptr
instances...
But if there's a well-defined time at which you want to free your
whole linked structure, it would be simpler to put all nodes into a
memory pool that can be freed in one swell foop.
If your data structure is sufficiently similar across runs, you might
build it, run graph traversal as described above to identify cycles,
analyze those cycles and decide where to change shared_ptr to weak_ptr
for future runs.
But that tactic wouldn't work if the data structure varies wildly with
different input data.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net