-
Creator 版本:2.4.4
-
目标平台: chome浏览器调试
-
重现方式:动态加载预制体,释放预制体时观察它使用到的cc.SpriteFrame
如果不释放cc.SpriteFrame会越来越多,应该怎么去释放它
Creator 版本:2.4.4
目标平台: chome浏览器调试
重现方式:动态加载预制体,释放预制体时观察它使用到的cc.SpriteFrame
如果不释放cc.SpriteFrame会越来越多,应该怎么去释放它
我自己是这么释放的
···
/**
* 释放资源
*/
public releaseRes(path: string, bundleName: string = "resources", type: typeof cc.Asset, clear: boolean = false) {
const bundle = cc.assetManager.getBundle(bundleName);
if (!bundle) {
return 0;
}
const asset = bundle.get(path, type);
if (!asset) {
return 0;
}
if (asset.refCount > 0) {
asset.decRef();
}
if (clear) {
asset.refCount = 0;
}
if (asset.refCount <= 0) {
bundle.release(path);
}
//
// cc.assetManager.dependUtil.getDepsRecursively(asset.uuid);
return 0;
}
···
spriteFrame只是框选出texture的一个矩形区域,所以理论上spriteFrame是不占用资源内存的,就spriteFrame其实只是资源的一个引用,如果想要释放内存,即释放texture