19 Mar
2009
19 Mar
'09
2:34 p.m.
On Wed, Mar 18, 2009 at 20:28, Ben
Consider the following:
void createSharePtr( boost::shared_ptr<int> value) { value.reset( new int(100)); }
main() { boost::shared_ptr<int> y( new int(0)); createSharePtr( y); };
Question: Does the function createSharePtr() cause memory leak?
No. Consider creating a class which outputs text in the constructors and destructor. Then you can run various things with that and see the destructor getting called as evidence of the memory being released. Overall -- apart from creating cycles -- you have to do something rather silly to make shared_ptr leak (like doing memset(&y, 0, sizeof(shared_ptr<int>));).