class
CC_DLL
Ref
@H_404_25@{
@H_404_25@{
@H_404_25@
CCASSERT
@H_404_25@(_referenceCount > 0,
"reference count should greater than 0"
@H_404_25@);
@H_404_25@ ++_referenceCount;
@H_404_25@}
@H_404_25@
/**
引用计数-1
*/
@H_404_25@{
@H_404_25@
CCASSERT
@H_404_25@(_referenceCount > 0,
"reference count should greater than 0"
@H_404_25@);
@H_404_25@ --_referenceCount;
@H_404_25@ {
@H_404_25@
if
@H_404_25@(!poolManager->getCurrentPool()->isClearing() && poolManager->isObjectInPools(
this
@H_404_25@))
@H_404_25@ {
@H_404_25@
// auto obj = Node::create();
@H_404_25@
// obj->autorelease();
//create函数里面封装了
autorelease
@H_404_25@
@H_404_25@
// auto obj = Node::create();
@H_404_25@
// obj->release(); // Wrong: obj is an autorelease Ref,it will be released when clearing current pool.
@H_404_25@
CCASSERT
@H_404_25@(
false
@H_404_25@,
"The reference shouldn't be 0 because it is still in autorelease pool."
@H_404_25@);
@H_404_25@ }
#endif
@H_404_25@
#if
CC_USE_MEM_LEAK_DETECTION
#endif
@H_404_25@ }
@H_404_25@
/**
*/
@H_404_25@
/**
* 返回引用数量
*/
@H_404_25@
@H_404_25@
/**
* 在构造了之后引用计数是1!!!!!
*/
@H_404_25@ Ref()
@H_404_25@
/// count of references
#if
CC_ENABLE_SCRIPT_BINDING
@H_404_25@
/// object id,ScriptSupport need public _ID
@H_404_25@
/// Lua reference id
#endif
#if
CC_USE_MEM_LEAK_DETECTION
#endif
@H_404_25@};
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
PoolManager类的解析:
class
CC_DLL
PoolManager
@H_404_25@{
@H_404_25@ //这个是表示这个接口以后要丢弃
@H_404_25@
CC_DEPRECATED_ATTRIBUTE
static
PoolManager
@H_404_25@* sharedPoolManager() {
return
@H_404_25@getInstance(); }
@H_404_25@
@H_404_25@{
@H_404_25@ {
@H_404_25@
// Add the first auto release pool
@H_404_25@ s_singleInstance->_curReleasePool =
new
AutoreleasePool
@H_404_25@(
"cocos2d autorelease pool"
@H_404_25@);
@H_404_25@ s_singleInstance->_releasePoolStack.push_back(s_singleInstance->_curReleasePool);
@H_404_25@ }
@H_404_25@}
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
/**
* 获得现在的释放池,引擎自己创建了一个autoreleasePool
* 你可以创建自己的释放池 会放进自动释放池的盏变量里面
*/
@H_404_25@
@H_404_25@ PoolManager();
@H_404_25@ ~PoolManager();
@H_404_25@{
@H_404_25@
// 如果是弹出第一个
@H_404_25@
@H_404_25@ _releasePoolStack.pop_back();
@H_404_25@
@H_404_25@ {
@H_404_25@ _curReleasePool = _releasePoolStack.back();
@H_404_25@ }
@H_404_25@}
@H_404_25@
@H_404_25@};
@H_404_25@
AutoreleasePool
class
CC_DLL
AutoreleasePool
@H_404_25@{
@H_404_25@
/**
* 创建的时候就自动push进PoolManager里面
*/
@H_404_25@ AutoreleasePool();
@H_404_25@
/**
* 用引用来创建 是为了调试
*/
@H_404_25@ _managedObjectArray.reserve(150);
@H_404_25@}
//
枚举每一个加进对象池的obj去调用release 并且清空
@H_404_25@ ~AutoreleasePool();
@H_404_25@
/**
* 添加对象到对象池中
* 对象池销毁的时候会调用
*/
@H_404_25@
/**
*/
#endif
@H_404_25@ {
@H_404_25@ obj->release();
@H_404_25@ }
@H_404_25@
@H_404_25@ //把vector清空
@H_404_25@ _managedObjectArray.clear();
#endif
@H_404_25@}
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@
/**
* Whether the pool is doing `clear` operation.
*/
#endif
@H_404_25@
@H_404_25@
/**
* 检查是否包含
* 枚举一遍这个vector
*/
@H_404_25@
/**
* 用来调试
*
*/
@H_404_25@
CCLOG
@H_404_25@(
"autorelease pool: %s,number of managed object %d\n"
@H_404_25@,_name.c_str(),
static_cast
@H_404_25@<
int
@H_404_25@>(_managedObjectArray.size()));
@H_404_25@
CCLOG
@H_404_25@(
"%20s%20s%20s"
@H_404_25@,
"Object pointer"
@H_404_25@,
"Object id"
@H_404_25@,
"reference count"
@H_404_25@);
@H_404_25@ {
@H_404_25@ }
@H_404_25@}
@H_404_25@
@H_404_25@
@H_404_25@
/**
* The underlying array of object managed by the pool.
*
* Although Array retains the object once when an object is added,proper
* Ref::release() is called outside the array to make sure that the pool
* does not affect the managed object's reference count. So an object can
* be destructed properly by calling Ref::release() even if the object
* is in the pool.
*/
@H_404_25@
@H_404_25@
/**
* The flag for checking whether the pool is doing `clear` operation.
*/
#endif
@H_404_25@};
@H_404_25@
@H_404_25@
@H_404_25@
@H_404_25@下面这张图是网上找的类图继承图:
@H_404_25@
@H_404_25@