时间:2019-05-03 来源:小程序工厂
我也遇到了同样的问题 ,请问官方大大 有结果了吗 ?
removeLayer(layerName): boolean {
if (!layerName || !this._curScene) {
console.log("错误: layerName 或者 this._curScene 为空");
return false;
}
let layer = this._layers[layerName]
if (!layer) {
console.log("错误: 当前场景找不到layer", layerName);
return false;
}
this._curScene.removeChild(layer, true);
console.log("removeLayer::::",layerName)
this._layers[layerName] = null;
layer.destroy();
cc.sys.garbageCollect();
ResManager.getInstance().removeAll();
wx.triggerGC();
return true;
}
麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题
removeLayer ( layerName ): boolean {if (! layerName || ! this . _curScene ) {console . log ( "错误: layerName 或者 this._curScene 为空" );return false ;}let layer = this . _layers [ layerName ]if (! layer ) {console . log ( "错误: 当前场景找不到layer" , layerName );return false ;}this . _curScene . removeChild ( layer , true );console . log ( "removeLayer::::" , layerName )this . _layers [ layerName ] = null ;
layer . destroy ();cc . sys . garbageCollect ();
ResManager . getInstance (). removeAll ();wx.triggerGC(); return true ;}
编辑器是CocosCreator,动态加载的prefab和spriteFrame都有移除
...
let pfc=cc.instantiate(this.pop_free_coins);
this.destroyList[this.destroyList.length]=pfc;
pfc.parent=this.node;
...
onDestroy(){
for(let i=0;i>this.destroyList.length;i++){
this.destroyList[i].removeFromParent(true);
}
this.head_ico.removeFromParent(true);
}
但是在微信开发版环境下内存总体一直增加
@晨 能不能给外解决方案,这么多天了也不理!
@晨 再不解决,我要被项目经理喷了........
这个问题从提问到现在已过去近半个月了也没人跟进下.....
解决了吗? 有没有解决方式?
目前临时的解决方案是尽量减少 cc.Instantiate 的使用次数,感觉是每创建一次都会造成内存增加,并且很难降下来
官方现在是什么态度,其实我到现在都还不知道原因,你说的cc.instantiate我没怎么用到过,而且可以确定的是我在看到有明显内存增长,是没有执行过cc.instantiate
同样受这个问题困扰中,内存不断增加,不会下降,研究了5天了,没有解决,在这里发现还有这么多同行.......
目前临时的解决方案是尽量减少 cc.Instantiate 的使用次数,感觉是每创建一次都会造成内存增加,并且很难降下来