Boost C++ Libraries: Ticket #593: shared_ptr<> causes memory leacks and crash https://svn.boost.org/trac10/ticket/593 <pre class="wiki">I have written this small test to reproduce the bug. Please see.. #include &lt;cstddef&gt; #include &lt;boost/shared_ptr.hpp&gt; #include &lt;boost/test/unit_test.hpp&gt; using namespace std; using namespace boost; using namespace boost::unit_test_framework; class A; class B { public: B(boost::shared_ptr&lt;A&gt; ptr) : ptr_(ptr) {} ~B() {} private: boost::shared_ptr&lt;A&gt; ptr_; }; class A { public: A(int value) : value_(value) {} ~A() {} private: int value_; }; void test_shared_ptr() { BOOST_CHECKPOINT("Testing shared pointer..."); shared_ptr&lt;A&gt; a1(new A(10)); { shared_ptr&lt;B&gt; b1 = a1-&gt;create(); } { shared_ptr&lt;B&gt; b1 = a1-&gt;create(); } } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/593 Trac 1.4.3 Peter Dimov Thu, 23 Mar 2006 20:02:43 GMT <link>https://svn.boost.org/trac10/ticket/593#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/593#comment:1</guid> <description> <pre class="wiki">Logged In: YES user_id=305912 Your test doesn't compile since A doesn't define a 'create' member function; if I fix it to use new B(a1) instead, it doesn't link: unresolved external symbol "class boost::unit_test::test_suite * __cdecl init_unit_test_suite(int,char * * const)" What is your platform? What is your compiler? Does the problem occur with the CVS version? Is this report by Howard Hinnant: http://lists.boost.org/Archives/boost/2006/03/102122.php relevant? </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>vlazarenko</dc:creator> <pubDate>Fri, 24 Mar 2006 10:02:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/593#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/593#comment:2</guid> <description> <pre class="wiki">Logged In: YES user_id=1024198 Sorry, I forgot to add "create" method. It is something like this: shared_ptr&lt;B&gt; A::create() { return shared_ptr&lt;B&gt;(new B(shared_ptr&lt;A&gt;(this))); } I use Windows XP SP2, MS Visual Studio 2003 and boost downloaded from SF.net version 1.33.1. Actually, I am a little bit sorry, because it isn't a bug, maybe issue. Code compiles OK, but works only with using "boost::enable_shared_from_this&lt;A&gt;" inheritance of A class. It was hard to find in documentation a little and may confuse developers (like me :)) Maybe it would be good to write it in documentation using red color. Thanks </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Wed, 17 May 2006 22:43:00 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/593#comment:3 https://svn.boost.org/trac10/ticket/593#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> </ul> Ticket