Boost C++ Libraries: Ticket #445: Can't delete automatically in circularly included object. https://svn.boost.org/trac10/ticket/445 <pre class="wiki">hi,all: I am a chinese student.Please forgive me because of my poor english. I found an error on smart pointer shared_ptr when i add an shared_ptr object to itself. The code is below.Class StatusBase is a subclass of Status.There is a method name addEventResult in class StatusBase. As you can see, EventResult is an object which made up of object Status( StatusBase actually because of Status is an abstract class ),Action and Event.In the case, I try to let them passed in share_ptr wrpper whenever in constructor or normal method.As my opinion,I think that will not be error and when I exit my program it will free the memory for me automatically. But in fact it will not. shared_ptr&lt;Status&gt; A( new Status() ); shared_ptr&lt;Event&gt; B( new Event() ); shared_ptr&lt;Action&gt; C( new Action() ); shared_ptr&lt;EventResult&gt; ABC( new EventResult( A, B, C ) ); //the row below will result the object A can't be released, so as to the object ABC , B and C A.addEventResult( ABC ); //next is about the decleartion of StatusBase and EventResult. For class Event and Action, it is the history. class StatusBase : public Status //{{{ { public: StatusBase(){} virtual ~StatusBase(){} public: int getEventResultCount() const ; boost::shared_ptr&lt;EventResult&gt; getEventResult( int index ) const ; void addEventResult( const boost::shared_ptr&lt;EventResult&gt;&amp; v ) ; private: std::vector&lt; boost::shared_ptr&lt;EventResult&gt; &gt; events ; }; //}}} class EventResult : public pqkit::Object //{{{ { public: EventResult( const boost::shared_ptr&lt;Event&gt;&amp; e, const boost::shared_ptr&lt;Action&gt;&amp; a, const boost::shared_ptr&lt;Status&gt;&amp; s ) : event(e),action (a),newStatus(s){} virtual ~EventResult() {} public: virtual const std::string toString() const { return Object::toString() ; } virtual const pqkit::Class getClass() const { return pqkit::Class("EventResult","inhert:Object-&gt;EventResult"); } boost::shared_ptr&lt;Event&gt; getEvent() const { return event; } boost::shared_ptr&lt;Action&gt; getAction() const { return action; } boost::shared_ptr&lt;Status&gt; getNewStatus() const { return newStatus; } private: boost::shared_ptr&lt;Event&gt; event ; boost::shared_ptr&lt;Action&gt; action ; boost::shared_ptr&lt;Status&gt; newStatus ; }; //}}} yours JinheZeng at GDUT from China. </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/445 Trac 1.4.3 Peter Dimov Thu, 06 Oct 2005 18:48:34 GMT <link>https://svn.boost.org/trac10/ticket/445#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/445#comment:1</guid> <description> <pre class="wiki">Logged In: YES user_id=305912 The inability to free circular references is a documented limitation of shared_ptr and not a bug. I'm moving this to Feature Requests. </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Peter Dimov</dc:creator> <pubDate>Sat, 07 Jul 2007 17:44:21 GMT</pubDate> <title>severity, milestone set https://svn.boost.org/trac10/ticket/445#comment:2 https://svn.boost.org/trac10/ticket/445#comment:2 <ul> <li><strong>severity</strong> → <span class="trac-field-new">Problem</span> </li> <li><strong>milestone</strong> → <span class="trac-field-new">To Be Determined</span> </li> </ul> Ticket Peter Dimov Thu, 26 Nov 2009 22:19:43 GMT status, resolution changed https://svn.boost.org/trac10/ticket/445#comment:3 https://svn.boost.org/trac10/ticket/445#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">wontfix</span> </li> </ul> Ticket