C ++参考计数更改同时销毁对象 [英] C++ Ref Count Changes While Destructing Object

查看:143
本文介绍了C ++参考计数更改同时销毁对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在类SharedObject中有一个私人引用计数。 SharedObject是其他类的基类,例如Window。

I've got a private ref count inside the class SharedObject. SharedObject is a base class for other classes, for example Window. Window is the base class of Editor.

当引用计数达到0时,由于调用SharedObject :: Release(),SharedObject会删除它自己。首先我们得到编译器析构函数,它显示这个指针包含m_refs == 0,但是当我们得到窗口析构函数时,它突然变为1,当我们到达SharedObject析构函数时,它仍然是1。

When the ref count reaches 0, because of calling SharedObject::Release(), the SharedObject deletes itself. First we get to the Editor destructor, which shows that the this pointer contains m_refs == 0, but when we get to the Window destructor it is suddenly 1, and when we reach the SharedObject destructor, it is still 1.

我在SharedObject :: IncRef()方法上设置了一个断点,并且在发生这种情况时从未调用过。

I put a breakpoint on the SharedObject::IncRef() method, and it was never called while this happened.

推荐答案

使用优化关闭构建,并在m_refs上设置内存断点。

Build with optimizations off, and set a memory breakpoint on your m_refs.

这篇关于C ++参考计数更改同时销毁对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆