Files
XCSDD/docs/api/core/refcounted/Release.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- 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
2026-03-19 12:44:08 +08:00

796 B
Raw Blame History

RefCounted::Release

void Release();

减少引用计数。

描述

原子地减少引用计数。当引用计数归零时,对象会自动 delete this。这是实现自动内存管理的关键方法。

复杂度: O(1)(归零时为 O(n)n 为对象大小)

示例:

#include <XCEngine/Core/RefCounted.h>

class MyObject : public RefCounted {
public:
    void DoSomething() { /* ... */ }
};

// 创建对象(构造时 refCount = 1
MyObject* obj = new MyObject();

// 手动增加引用
obj->AddRef();  // refCount = 2

// 释放引用
obj->Release();  // refCount = 1
obj->Release();  // refCount = 0, 对象被自动 delete

相关文档