如何释放 cocos js 内存

我在场景里面创建了100个sprite 在场景切换的时候,内存并没有释放,有释放图片资源,但是内存减不下来。

sprite frame cache是否有释放?另外,你是在什么平台测试的?

在ios 平台 用的cocos js 3.14.1

到现在都还是一样 没释放
我只使用一个数组 , 创建生成 数组清除的时候 内存也没有下降@minggo 求大神看看
var TextLayer = cc.Layer.extend({
sprite:null,
ctor:function () {
//////////////////////////////
// 1. super init first
this._super();
this.sprArray = [];
/////////////////////////////
// 2. add a menu item with “X” image, which is clicked to quit the program
// you may modify it.
// ask the window size
var size = cc.winSize;

    /////////////////////////////
    // 3. add your codes below...
    // add a label shows "Hello World"
    // create and initialize a label
    var helloLabel = new cc.LabelTTF("Hello World", "Arial", 38);
    // position the label on the center of the screen
    helloLabel.x = size.width / 2;
    helloLabel.y = size.height / 2 + 200;
    // add the label as a child to this layer
    this.addChild(helloLabel, 5);

    // add "HelloWorld" splash screen"
    this.sprite = new ccui.ImageView(res.HelloWorld_png);
    this.sprite.setColor(cc.color(255, 0, 0));
    this.sprite.attr({
        x: size.width / 3,
        y: size.height / 2
    });
    this.addChild(this.sprite, 0);
    this.sprite.setTouchEnabled(true);

    this.spriteCallBack2 = function(){
        cc.log("spriteCallBack2", this.sprArray.length);
        //var len = this.sprArray.length;
        // for (var i = 0; i < len; i++){
        //     var number = this.sprArray.pop()
        //     number = null;
        // }
        cc.log("spriteCallBack2", this.sprArray.length);
        this.sprArray = [];
        cc.log("spriteCallBack2", this.sprArray.length);
        //this.sprArray = null;
        this.spriteCallBack2 = null;
    }.bind(this);


    this.sprite.addClickEventListener(this.spriteCallBack2);


    // add "HelloWorld" splash screen"
    this.sprite = new ccui.ImageView(res.HelloWorld_png);
    this.sprite.setColor(cc.color(255, 255, 0));
    this.sprite.attr({
        x: size.width / 3 * 2,
        y: size.height / 2
    });
    this.addChild(this.sprite, 0);
    this.sprite.setTouchEnabled(true);
    
    this.spriteCallBack1 = function(){
        this.addSprite();
    }.bind(this);
    
    this.sprite.addClickEventListener(this.spriteCallBack1);



    this.sprite = new ccui.ImageView(res.HelloWorld_png);
    this.sprite.attr({
        x: size.width / 4,
        y: size.height / 4
    });
    this.addChild(this.sprite, 0);
    this.sprite.setTouchEnabled(true);
    this.sprite.addClickEventListener(function () {
        cc.director.runScene(new HelloWorldScene());
    }.bind(this));

    return true;
},

addSprite :function () {
    for(var i = 0; i < 10000; ++i){
        //var img = new cc.Sprite(res.HelloWorld_png);
        //this.addChild(img, 0);
        var img = 100;
        this.sprArray.push(img);
    }
    cc.log("addSprite", this.sprArray.length);
},

onEnter : function () {
    this._super();
    // for (var i in this.sprArray){
    //     this.sprArray[i] = undefined;
    // }
   // cc.SpriteFrameCache.getInstance().removeSpriteFrames();
    //cc.TextureCache.getInstance().removeAllTextures();
},

onExit : function(){
    this._super();
    // for(var i in this.sprArray){
    //     //this.sprArray[i].removeFromParentAndCleanup(true);
    //     this.sprArray[i] = {};
    //     delete this.sprArray[i];
    // }

    this.sprArray = [];
    //delete this.sprArray;
},

});

var TextScene = cc.Scene.extend({
onEnter:function () {
this._super();
var layer = new TextLayer();
this.addChild(layer);
}
});

this 可能被 click event listener 持有了,导致泄漏,可以试试在 exit 的时候删除 event listener,可能可以

this.sprite.addClickEventListener(null);

添加了之后 还是没有释放
我现在的项目就是一直看不着释放 最后 JS_CallFunctionValue(cx, target, callback, args, &retval);在这里就崩溃了,提示
malloc: *** error for object 0x1: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug

目测this.sprite,this.spriteCallback…都需要设置为null
数组重置可以使用 arr.length=0