[LayaAir 2.0]Skeleton骨骼动画内存泄漏

问题描述:
快捷键1创建骨骼动画,快捷键2销毁骨骼动画,如此重复,FPS内存会一直往上升,降不下来。
1.png

2.png

3.png

核心代码如下:
	private te:Laya.Templet;
private sk:Laya.Skeleton;

private onKeyDown(e):void{
if(e.keyCode == 49 || e.keyCode == 97){
if(this.te == null){
this.te = new Laya.Templet();
this.te.on(Laya.Event.COMPLETE, this, this.teComplete);
this.te.loadAni("res/wing_01_side.sk");
}
} else if(e.keyCode == 50 || e.keyCode == 98) {
if(this.te != null){
this.te.destroy();
this.te = null;
this.sk.destroy();
this.sk = null;
}
}
}

private teComplete():void{
this.sk = this.te.buildArmature(0);
this.sk.x = 400;
this.sk.y = 700;
this.sk.play(0, true);
Laya.stage.addChild(this.sk);
}

Demo如下:
已邀请:

Lee3260

赞同来自:

我这边也存在db泄露 关注了

sky1989chen

赞同来自:

Templet 不要重复创建。

Anydo

赞同来自:

顶起。问题未解决。

五月

赞同来自:

原因好像是CacheStyle有错误CacheStyle.releaseContext时 canvas的一些引用没清理干净就丢回池里去了
 
如下这些都清理一下看看
 
canvas.context = null;
canvas.touches = null;
//记录的文字信息。cacheas normal的话,文字要能正确touch
canvas.submits = null;
// 从context中剪切的submit
canvas.sprite = null;
// submit需要关联稳定独立的mesh。所以这里要创建自己的mesh对象
canvas._mesh = null;
//用Mesh2D代替_vb,_ib. 当前使用的mesh
canvas._pathMesh = null;
//矢量专用mesh。
canvas._triangleMesh = null;
//drawTriangles专用mesh。由于ib不固定,所以不能与_mesh通用
canvas.meshlist = null;
// 原始context的原始值
canvas._oldMesh = null;
canvas._oldPathMesh = null;
canvas._oldTriMesh = null;
canvas._oldMeshList = null;
canvas.oldMatrix = null;

Aar0n

赞同来自:

下个版本就好了,之前已经修复

Lee3260

赞同来自:

持续关注。。

Lee3260

赞同来自:

请问 这个问题 有答复或者修复了吗

lzsong

赞同来自:

貌似遇到过类似问题,laya.ani.js中修改这段代码试试是不是资源没销毁
        if (this.url){
            delete Templet.TEMPLET_DICTIONARY[this.url];
        }
换成
        if (this._relativeUrl){
            delete Templet.TEMPLET_DICTIONARY[this._relativeUrl];
        }

Lee3260

赞同来自:

2.0.0版本下 已经解决这个问题 
修改
laya.core.js
var Texture 对象里
__proto.destroy=function(){
if (!this._destroyed){
this._destroyed=true;
if (this.bitmap){
this.bitmap._removeReference(this._referenceCount);
if (this.bitmap.referenceCount===0){
this.bitmap.destroy();
// console.log("texture2d destory");
}
this.bitmap=null;
}
if (this.url && this===Laya.loader.getRes(this.url))
Laya.loader.clearRes(this.url);
}
}
增加的代码是 
if (this.bitmap.referenceCount===0){
this.bitmap.destroy();
// console.log("texture2d destory");
}

打点酱油

赞同来自:

请问下这个咋解决啊,我也碰到这个问题

要回复问题请先

商务合作
商务合作