Boost logo

Boost Users :

Subject: Re: [Boost-users] share_ptr reset() question
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2009-03-19 10:34:51


On Wed, Mar 18, 2009 at 20:28, Ben <befung_at_[hidden]> wrote:
>
> 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>));).


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net