31 Jul
2020
31 Jul
'20
8:42 p.m.
逸霖 杨 wrote:
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.