Boost logo

Boost :

From: ÒÝÁØ Ñî (yyl_20050115_at_[hidden])
Date: 2020-07-31 21:11:19



> Please check code on
> https://github.com/yyl-20020115/RCGC

As far as I can tell, rcgc_shared_ptr<T> calls the destructor of T as soon
as its destructor is invoked, regardless of whether other references exist.
That is,

int main()
{
    rcgc_shared_ptr<X> p1( new X );

    {
        rcgc_shared_ptr<X> p2( p1 );
    } // ~X is called here

    // *p1 references a destroyed object here
}

This doesn't seem correct to me; the point of shared_ptr is to not call the
destructor of the pointee as long as references (such as p1 in the code
above) exist to it.


---
My bad answer.
There is only one object generated by new X().
But as I said before if you use rcgc_shared_ptr with the field objects of X, no worry
Of multiple freeing. Because the reference count is in charge.





Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk