Ref::~Ref() { #if CC_ENABLE_SCRIPT_BINDING // if the object is referenced by Lua engine, remove it if (_luaID) { ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptObjectByObject(this); } #if !CC_ENABLE_GC_FOR_NATIVE_OBJECTS else { ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); if (pEngine != nullptr && pEngine->getScriptType() == kScriptTypeJavascript) { pEngine->removeScriptObjectByObject(this); } } #endif // !CC_ENABLE_GC_FOR_NATIVE_OBJECTS #endif // CC_ENABLE_SCRIPT_BINDING #if CC_REF_LEAK_DETECTION if (_referenceCount != 0) untrackRef(this); #endif }
Ref::~Ref() { #if CC_ENABLE_SCRIPT_BINDING // if the object is referenced by Lua engine, remove it if (_luaID) { ScriptEngineManager::getInstance()->getScriptEngine()->removeScriptObjectByObject(this); } else { ScriptEngineProtocol* pEngine = ScriptEngineManager::getInstance()->getScriptEngine(); if (pEngine != NULL && pEngine->getScriptType() == kScriptTypeJavascript) { pEngine->removeScriptObjectByObject(this); } } #endif #if CC_USE_MEM_LEAK_DETECTION if (_referenceCount != 0) // delete this object from list untrackRef(this); #endif }
void Ref::release() { CCASSERT(_referenceCount > 0, "reference count should be greater than 0"); --_referenceCount; #if CC_ENABLE_SCRIPT_BINDING && CC_ENABLE_GC_FOR_NATIVE_OBJECTS if (_scriptOwned && _rooted && _referenceCount==/*_referenceCountAtRootTime*/ 1) { auto scriptMgr = ScriptEngineManager::getInstance()->getScriptEngine(); if (scriptMgr && scriptMgr->getScriptType() == kScriptTypeJavascript) { scriptMgr->unrootObject(this); } } #endif // CC_ENABLE_SCRIPT_BINDING if (_referenceCount == 0) { #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) auto poolManager = PoolManager::getInstance(); if (!poolManager->getCurrentPool()->isClearing() && poolManager->isObjectInPools(this)) { // Trigger an assert if the reference count is 0 but the Ref is still in autorelease pool. // This happens when 'autorelease/release' were not used in pairs with 'new/retain'. // // Wrong usage (1): // // auto obj = Node::create(); // Ref = 1, but it's an autorelease Ref which means it was in the autorelease pool. // obj->autorelease(); // Wrong: If you wish to invoke autorelease several times, you should retain `obj` first. // // Wrong usage (2): // // auto obj = Node::create(); // obj->release(); // Wrong: obj is an autorelease Ref, it will be released when clearing current pool. // // Correct usage (1): // // auto obj = Node::create(); // |- new Node(); // `new` is the pair of the `autorelease` of next line // |- autorelease(); // The pair of `new Node`. // // obj->retain(); // obj->autorelease(); // This `autorelease` is the pair of `retain` of previous line. // // Correct usage (2): // // auto obj = Node::create(); // obj->retain(); // obj->release(); // This `release` is the pair of `retain` of previous line. CCASSERT(false, "The reference shouldn't be 0 because it is still in autorelease pool."); } #endif #if CC_REF_LEAK_DETECTION untrackRef(this); #endif delete this; } }
void Ref::release() { if ((--_refCount) <= 0) { #ifdef GAMEPLAY_MEM_LEAK_DETECTION untrackRef(this, __record); #endif delete this; } }
void Ref::release() { CCASSERT(_referenceCount > 0, "reference count should greater than 0"); --_referenceCount; if (_referenceCount == 0) { #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) auto poolManager = PoolManager::getInstance(); if (!poolManager->getCurrentPool()->isClearing() && poolManager->isObjectInPools(this)) { // Trigger an assert if the reference count is 0 but the Ref is still in autorelease pool. // This happens when 'autorelease/release' were not used in pairs with 'new/retain'. // // Wrong usage (1): // // auto obj = Node::create(); // Ref = 1, but it's an autorelease Ref which means it was in the autorelease pool. // obj->autorelease(); // Wrong: If you wish to invoke autorelease several times, you should retain `obj` first. // // Wrong usage (2): // // auto obj = Node::create(); // obj->release(); // Wrong: obj is an autorelease Ref, it will be released when clearing current pool. // // Correct usage (1): // // auto obj = Node::create(); // |- new Node(); // `new` is the pair of the `autorelease` of next line // |- autorelease(); // The pair of `new Node`. // // obj->retain(); // obj->autorelease(); // This `autorelease` is the pair of `retain` of previous line. // // Correct usage (2): // // auto obj = Node::create(); // obj->retain(); // obj->release(); // This `release` is the pair of `retain` of previous line. CCASSERT(false, "The reference shouldn't be 0 because it is still in autorelease pool."); } #endif #if CC_USE_MEM_LEAK_DETECTION untrackRef(this); #endif delete this; } }
void Ref::release() { CCASSERT(_referenceCount > 0, "reference count should be greater than 0"); if(_referenceCount <= 0){ return; } --_referenceCount; auto poolManager = PoolManager::getInstance(); if (_isInAutoPool&&poolManager->isClearing()) { _isInAutoPool = false; } if (_referenceCount == 0) { //auto poolManager = PoolManager::getInstance(); if (_isInAutoPool&&!poolManager->isClearing() )//&& poolManager->isObjectInPools(this)) { poolManager->removeObject(this); } #if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) // auto poolManager = PoolManager::getInstance(); // if (!poolManager->getCurrentPool()->isClearing() && poolManager->isObjectInPools(this)) // { // } // Trigger an assert if the reference count is 0 but the Ref is still in autorelease pool. // This happens when 'autorelease/release' were not used in pairs with 'new/retain'. // // Wrong usage (1): // // auto obj = Node::create(); // Ref = 1, but it's an autorelease Ref which means it was in the autorelease pool. // obj->autorelease(); // Wrong: If you wish to invoke autorelease several times, you should retain `obj` first. // // Wrong usage (2): // // auto obj = Node::create(); // obj->release(); // Wrong: obj is an autorelease Ref, it will be released when clearing current pool. // // Correct usage (1): // // auto obj = Node::create(); // |- new Node(); // `new` is the pair of the `autorelease` of next line // |- autorelease(); // The pair of `new Node`. // // obj->retain(); // obj->autorelease(); // This `autorelease` is the pair of `retain` of previous line. // // Correct usage (2): // // auto obj = Node::create(); // obj->retain(); // obj->release(); // This `release` is the pair of `retain` of previous line. // CCASSERT(false, "The reference shouldn't be 0 because it is still in autorelease pool."); // } #endif #if CC_REF_LEAK_DETECTION untrackRef(this); #endif if ( g_performanceCrashSwitch && _isInAutoPool && !poolManager->isClearing() ) { #ifdef CC_ENABLE_BACKTRACE const size_t max = 30; void* buffer[max]; dumpBacktrace( buffer, captureBacktrace(buffer, max)); #endif int *pTest = NULL; *pTest = 123456; } delete this; } }
Ref::~Ref() { untrackRef(this); }