Is there any cache clean function in playcanvas?
My script just clone the avatar and destroy when I click the button.
But It seems to be there are some memory leak, so I want to refresh the memory when destroy clones.
This is my code.
var CloneTest = pc.createScript('cloneTest');
var d;
// Initialize code called once per entity
CloneTest.prototype.initialize = function() {
// Register the mouse down and touch start event so we know when the user has clicked
start_as = pc.app.root.findByName("Button_as");
pause_ax = pc.app.root.findByName("Button_ax");
stop_ax = pc.app.root.findByName("Button_ad");
f=pc.app.root.children;
count_a = pc.app.root.findByTag("avatarcount")[0].element;
console.log(count_a.text);
start_as.button.on('click', function(event){
if(event.button == pc.MOUSEBUTTON_LEFT){
d=true;
setInterval(function(){
this.TestClone(event);
if(d==true){
console.log("clone start! " + "Avatar: " + f.length);
count_a.text=f.length;
console.log(f.length);
console.log(d);
}
}.bind(this),1000);
}
},this);
pause_ax.button.on('click',function(event){
if(event.button == pc.MOUSEBUTTON_LEFT){
d=false;
}
}, this);
pause_ax.button.on('touchstart',function(event){
d=false;
}, this);
stop_ax.button.on('click',function(event){
if(event.button == pc.MOUSEBUTTON_LEFT){
this.DeleteClone(event);}
count_a.text=f.length;
}, this);
stop_ax.button.on('touchstart',function(event){
this.DeleteClone(event);
count_a.text=f.length;
}, this);
};
CloneTest.prototype.TestClone = function(event) {
if(d==true){
cloned = pc.app.root.findByName("POC_dance");
e = cloned.clone(); // Clone Entity
e.setPosition(0,0,0);
this.app.root.addChild(e);
} else if (d == false){
}
};
CloneTest.prototype.DeleteClone = function(event) {
for (var k = f.length - 1; k >= 1; k--) {
r=pc.app.root.children[k];
r.destroy(); // destroy Entity
}
};