我写了个测试
在start()将Prefab载入
又用scheduleOnce(…)讲Prefab释放
又用scheduleOnce(…)讲Prefab载入
连续重复
ex.
start(){
this.onLoadRes();
}
onLoadRes() {
cc.loader.loadRes("Prefab/HelloWorld", cc.Prefab, (error: Error, prefab: cc.Prefab) => {
if (!error) {
cc.instantiate(prefab).parent = this.attachNode;
prefab = null;
this.scheduleOnce(function(){this.onUnloadRes();},0.1);
}
});
}
onUnloadRes() {
this.attachNode.removeAllChildren(true);
var deps = cc.loader.getDependsRecursively('Prefab/HelloWorld');
cc.loader.release(deps);
cc.sys.garbageCollect();
this.onDump();
this.scheduleOnce(function(){this.onLoadRes();},0.1);
}
onDump() {
let Loader:any = cc.loader;
this.dumpLabel.string = `当前资源总数:${Object.keys(Loader._cache).length}`;
}
为何内存还会不断扩大?
是引擎的问题?
还是我的观念错误?
我的测试专案prefab_release_sample.zip (1.3 MB)