docs: update core and debug API docs
This commit is contained in:
@@ -4,33 +4,40 @@
|
||||
void Release();
|
||||
```
|
||||
|
||||
减少引用计数。
|
||||
原子地减少引用计数。
|
||||
|
||||
**描述**
|
||||
|
||||
原子地减少引用计数。当引用计数归零时,对象会自动 `delete this`。这是实现自动内存管理的关键方法。
|
||||
|
||||
**复杂度:** O(1)(归零时为 O(n),n 为对象大小)
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Core/RefCounted.h>
|
||||
#include <cstdio>
|
||||
|
||||
class MyObject : public RefCounted {
|
||||
class MyObject : public XCEngine::Core::RefCounted {
|
||||
public:
|
||||
void DoSomething() { /* ... */ }
|
||||
void DoSomething() { }
|
||||
};
|
||||
|
||||
// 创建对象(构造时 refCount = 1)
|
||||
MyObject* obj = new MyObject();
|
||||
|
||||
// 手动增加引用
|
||||
obj->AddRef(); // refCount = 2
|
||||
|
||||
// 释放引用
|
||||
obj->Release(); // refCount = 1
|
||||
obj->Release(); // refCount = 0, 对象被自动 delete
|
||||
int main() {
|
||||
MyObject* obj = new MyObject();
|
||||
printf("After create: %u\n", obj->GetRefCount());
|
||||
|
||||
obj->AddRef();
|
||||
printf("After AddRef: %u\n", obj->GetRefCount());
|
||||
|
||||
obj->Release();
|
||||
printf("After Release: %u\n", obj->GetRefCount());
|
||||
|
||||
obj->Release();
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
Reference in New Issue
Block a user