Skip to content

Commit

Permalink
Merge pull request cocos#1034 from jareguo/v1.2
Browse files Browse the repository at this point in the history
auto release cached SpriteFrame
  • Loading branch information
nantas authored Aug 15, 2016
2 parents 02c5a9b + 7bab9fc commit 1b6f512
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
3 changes: 2 additions & 1 deletion cocos2d/core/load-pipeline/CCLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,9 @@ JS.mixin(CCLoader.prototype, {

// override
removeItem: function (key) {
this._baseRemoveItem(key);
var removed = this._baseRemoveItem(key);
delete this._autoReleaseSetting[key];
return removed;
},

/**
Expand Down
13 changes: 5 additions & 8 deletions cocos2d/core/load-pipeline/auto-release-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ function release (loader, key, nextSceneAssets) {
if (!nextSceneAssets || nextSceneAssets.indexOf(key) === -1) {
var item = loader.getItem(key);
if (item) {
loader.removeItem(key);
var removed = loader.removeItem(key);
console.log('auto release: ' + key);
// TODO: Audio
var asset = item.content;
if (asset instanceof cc.Texture2D) {
cc.textureCache.removeTextureForKey(item.url);
}
//else if (asset instanceof cc.SpriteFrame) {
// // for the "Temporary solution" in deserialize.js
// console.log('release sprite frame: ' + key);
// if (CC_JSB) {
// asset.release();
// }
//}
else if (CC_JSB && asset instanceof cc.SpriteFrame && removed) {
// for the "Temporary solution" in deserialize.js
asset.release();
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions cocos2d/core/load-pipeline/pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ JS.mixin(Pipeline.prototype, {
this.flowOut(item);
}
this._items.removeItem(url);
return true;
}
else {
return false;
Expand Down
2 changes: 1 addition & 1 deletion jsb/jsb-tex-sprite-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require('../cocos2d/core/assets/CCAsset');
// cc.SpriteFrameAnimation = cc.Animation;

// cc.textureCache.cacheImage

cc.textureCache._textures = {};
cc.textureCache.cacheImage = function (key, texture) {
if (texture instanceof cc.Texture2D) {
Expand Down Expand Up @@ -75,7 +76,6 @@ prototype.textureLoaded = function () {
return this.getTexture() !== null;
};

// cc.SpriteFrame
prototype._ctor = function (filename, rect, rotated, offset, originalSize) {
this._name = '';
if (filename !== undefined) {
Expand Down

0 comments on commit 1b6f512

Please sign in to comment.