|
Boost Users : |
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2007-10-29 09:29:41
zzp good wrote:
> hi, guys, I found memory leak using the following code:
>
> #include <boost\array.hpp>
> #include <boost\shared_ptr.hpp>
> using namespace boost;
>
> class C
> {
> public:
> shared_ptr<C> pNext;
> };
>
> void test()
> {
> shared_ptr<C> c0(new C());
> shared_ptr<C> c1(new C());
> c0 -> pNext = c1;
> c1 -> pNext = c0;
> }
>
> void main()
> {
> test();
>
> _CrtDumpMemoryLeaks();
> }
See http://www.boost.org/libs/smart_ptr/weak_ptr.htm. It's specifically
designed to break these sorts of ownership cycles.
Jeff Flinn
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