diff --git a/cocos2d/core/CCNode.js b/cocos2d/core/CCNode.js index 0bb6984f74..13f8ba9efa 100644 --- a/cocos2d/core/CCNode.js +++ b/cocos2d/core/CCNode.js @@ -1378,7 +1378,7 @@ var Node = cc.Class({ return; cc.assertID(action, 1618); - if (CC_JSB) { + if (!cc.macro.ENABLE_GC_FOR_NATIVE_OBJECTS) { this._retainAction(action); this._sgNode._owner = this; } diff --git a/jsb/jsb-action.js b/jsb/jsb-action.js index 7f80c244aa..a0c024fc0d 100644 --- a/jsb/jsb-action.js +++ b/jsb/jsb-action.js @@ -23,6 +23,8 @@ THE SOFTWARE. ****************************************************************************/ +var ENABLE_GC_FOR_NATIVE_OBJECTS = cc.macro.ENABLE_GC_FOR_NATIVE_OBJECTS; + // Independent Action from retain/release var actionArr = [ 'ActionEase', @@ -100,15 +102,17 @@ function setAliasReplacer (name, type) { }; } -for (var i = 0; i < actionArr.length; ++i) { - var name = actionArr[i]; - var type = cc[name]; - if (!type) - continue; - var proto = type.prototype; - setCtorReplacer(proto); - if (name.indexOf('Ease') === -1) { - setAliasReplacer(name, type); +if (!ENABLE_GC_FOR_NATIVE_OBJECTS) { + for (var i = 0; i < actionArr.length; ++i) { + var name = actionArr[i]; + var type = cc[name]; + if (!type) + continue; + var proto = type.prototype; + setCtorReplacer(proto); + if (name.indexOf('Ease') === -1) { + setAliasReplacer(name, type); + } } } @@ -227,8 +231,10 @@ cc.callFunc = function (selector, selectorTarget, data) { selector.call(this, sender, data); }; var action = cc.CallFunc.create(callback, selectorTarget, data); - action.retain(); - action._retained = true; + if (!ENABLE_GC_FOR_NATIVE_OBJECTS) { + action.retain(); + action._retained = true; + } return action; }; @@ -244,8 +250,10 @@ cc.CallFunc.prototype._ctor = function (selector, selectorTarget, data) { this.initWithFunction(callback); else this.initWithFunction(callback, selectorTarget, data); } - this.retain(); - this._retained = true; + if (!ENABLE_GC_FOR_NATIVE_OBJECTS) { + this.retain(); + this._retained = true; + } }; function setChainFuncReplacer (proto, name) { @@ -262,19 +270,21 @@ function setChainFuncReplacer (proto, name) { }; } -setChainFuncReplacer(cc.ActionInterval.prototype, 'repeat'); -setChainFuncReplacer(cc.ActionInterval.prototype, 'repeatForever'); -setChainFuncReplacer(cc.ActionInterval.prototype, 'easing'); +if (!ENABLE_GC_FOR_NATIVE_OBJECTS) { + setChainFuncReplacer(cc.ActionInterval.prototype, 'repeat'); + setChainFuncReplacer(cc.ActionInterval.prototype, 'repeatForever'); + setChainFuncReplacer(cc.ActionInterval.prototype, 'easing'); -var jsbRunAction = cc.Node.prototype.runAction; -cc.Node.prototype.runAction = function (action) { - jsbRunAction.call(this, action); - if (action._retained) { - action.release(); - action._retained = false; - } - return action; -}; + var jsbRunAction = cc.Node.prototype.runAction; + cc.Node.prototype.runAction = function (action) { + jsbRunAction.call(this, action); + if (action._retained) { + action.release(); + action._retained = false; + } + return action; + }; +} function getSGTarget (target) { if (target instanceof cc.Component) { @@ -293,7 +303,7 @@ cc.ActionManager.prototype.addAction = function (action, target, paused) { target = getSGTarget(target); if (target) { jsbAddAction.call(this, action, target, paused); - if (action._retained) { + if (!ENABLE_GC_FOR_NATIVE_OBJECTS && action._retained) { action.release(); action._retained = false; } @@ -304,12 +314,18 @@ function actionMgrFuncReplacer (funcName, targetPos) { var proto = cc.ActionManager.prototype; var oldFunc = proto[funcName]; proto[funcName] = function () { - arguments[targetPos] = getSGTarget(arguments[targetPos]); - if (!arguments[targetPos]) { + var args = []; + for (var i = 0; i < arguments.length; i++) { + if (i === targetPos) + args[i] = getSGTarget(arguments[i]); + else + args[i] = arguments[i]; + } + if (!args[targetPos]) { return; } else { - return oldFunc.apply(this, arguments); + return oldFunc.apply(this, args); } }; } diff --git a/jsb/jsb-etc.js b/jsb/jsb-etc.js index 72665e1b5e..186fa509d9 100644 --- a/jsb/jsb-etc.js +++ b/jsb/jsb-etc.js @@ -25,8 +25,6 @@ 'use strict'; -var macro = require('../cocos2d/core/platform/CCMacro'); - cc.sys.now = function () { return Date.now(); }; @@ -216,8 +214,3 @@ cc.formatStr = cc.js.formatStr; if (cc.Image && cc.Image.setPNGPremultipliedAlphaEnabled) { cc.Image.setPNGPremultipliedAlphaEnabled(false); } - -// Mark memory model -if (window.__ENABLE_GC_FOR_NATIVE_OBJECTS__ !== undefined) { - macro.ENABLE_GC_FOR_NATIVE_OBJECTS = window.__ENABLE_GC_FOR_NATIVE_OBJECTS__; -} diff --git a/jsb/jsb-predefine.js b/jsb/jsb-predefine.js index 25ac09645d..b2fb7fc737 100644 --- a/jsb/jsb-predefine.js +++ b/jsb/jsb-predefine.js @@ -62,4 +62,11 @@ cc._initDebugSetting(cc.game.DEBUG_MODE_INFO); if (CC_DEV) { //Debug Info ID map require('../DebugInfos'); +} + +// Mark memory model +var macro = require('../cocos2d/core/platform/CCMacro'); + +if (window.__ENABLE_GC_FOR_NATIVE_OBJECTS__ !== undefined) { + macro.ENABLE_GC_FOR_NATIVE_OBJECTS = window.__ENABLE_GC_FOR_NATIVE_OBJECTS__; } \ No newline at end of file