Hello users. In the past, I wrote a program using the C++ built-in pointers. I made sure that there was not any memory leak: indeed, valgrind reported no memory leaks. I decided to switch to boost::shared_ptr, and replaced all the C++ built-in pointers with boost:shared_ptr ones. Interestingly, valgrind now reports a huge memory leak. I thought that by just replacing the built-in pointers with the boost::shared_ptr pointers (forgetting about explicit deletes of memory) would be enough. Note that I use boost::make_shared<> for memory allocations. I wish I could include the code in this email, but it is very long and complicated. Therefore, I am kindly asking you to guess what might have been wrong with the boost:shared_ptr. Could you think of any scenarios that would cause the observed bahavior? Any ideas would be welcome. OS: Ubuntu 64 Compiler: gcc version 4.4.3 Best Regards, Panagiotis Foteinos
On 27 March 2011 23:57, Panagiotis Foteinos
Hello users. Could you think of any scenarios that would cause the observed behaviour?
Any ideas would be welcome.
OS: Ubuntu 64 Compiler: gcc version 4.4.3
Best Regards, Panagiotis Foteinos
Sounds like cyclic references[1] for which you may need to use weak_ptr 's. [1]http://www.codeproject.com/KB/stl/boostsmartptr.aspx#Cyclic%20References
Thank you all for the replies.
Yes, this is the reason: cyclic references.
Regards,
Panagiotis Foteinos
On Sun, Mar 27, 2011 at 7:05 PM, liam mail
On 27 March 2011 23:57, Panagiotis Foteinos
wrote: Hello users. Could you think of any scenarios that would cause the observed behaviour?
Any ideas would be welcome.
OS: Ubuntu 64 Compiler: gcc version 4.4.3
Best Regards, Panagiotis Foteinos
Sounds like cyclic references[1] for which you may need to use weak_ptr 's. [1] http://www.codeproject.com/KB/stl/boostsmartptr.aspx#Cyclic%20References
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
I wish I could include the code in this email, but it is very long and complicated. Therefore, I am kindly asking you to guess what might have been wrong with the boost:shared_ptr. Could you think of any scenarios that would cause the observed bahavior?
Circular references. If A has shared_ptr to B, and B has shared_ptr to A, they both will never be release. To break such circular referencing, you should use weak_ptr for one direction.
participants (3)
-
Igor R
-
liam mail
-
Panagiotis Foteinos