Opened 17 years ago
Closed 16 years ago
#593 closed Bugs (Invalid)
shared_ptr<> causes memory leacks and crash
Reported by: | vlazarenko | Owned by: | Peter Dimov |
---|---|---|---|
Milestone: | Component: | smart_ptr | |
Version: | None | Severity: | |
Keywords: | Cc: |
Description
I have written this small test to reproduce the bug. Please see.. #include <cstddef> #include <boost/shared_ptr.hpp> #include <boost/test/unit_test.hpp> using namespace std; using namespace boost; using namespace boost::unit_test_framework; class A; class B { public: B(boost::shared_ptr<A> ptr) : ptr_(ptr) {} ~B() {} private: boost::shared_ptr<A> ptr_; }; class A { public: A(int value) : value_(value) {} ~A() {} private: int value_; }; void test_shared_ptr() { BOOST_CHECKPOINT("Testing shared pointer..."); shared_ptr<A> a1(new A(10)); { shared_ptr<B> b1 = a1->create(); } { shared_ptr<B> b1 = a1->create(); } }
Change History (3)
comment:2 by , 17 years ago
Logged In: YES user_id=1024198 Sorry, I forgot to add "create" method. It is something like this: shared_ptr<B> A::create() { return shared_ptr<B>(new B(shared_ptr<A>(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<A>" 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
comment:3 by , 16 years ago
Status: | assigned → closed |
---|
Note:
See TracTickets
for help on using tickets.