- Fix link resolution with proper relative/absolute path handling - Improve link styling with underline decoration - Hide leaf nodes from tree, only show directories - Fix log file path for packaged app
1.2 KiB
1.2 KiB
RefCounted
命名空间: XCEngine::Core
类型: class
描述: 引用计数基类,提供线程安全的引用计数生命周期管理。
概述
RefCounted 是一个简单的引用计数基类。当引用计数归零时,对象会自动删除。它提供了 AddRef 和 Release 方法,线程安全地管理引用计数。
公共方法
| 方法 | 描述 |
|---|---|
RefCounted() |
构造函数,初始引用计数为 1 |
virtual ~RefCounted() |
虚析构函数 |
AddRef |
增加引用计数 |
Release |
减少引用计数(归零时自动 delete this) |
GetRefCount |
获取当前引用计数 |
使用示例
class MyObject : public RefCounted {
public:
MyObject() { /* ... */ }
~MyObject() { /* ... */ }
void DoSomething() { /* ... */ }
};
// 使用
MyObject* obj = new MyObject(); // refCount = 1
obj->AddRef(); // refCount = 2
obj->Release(); // refCount = 1
obj->Release(); // refCount = 0, 自动 delete