Here is my code, I wonder if the delete is good enough to destroy an object and that there is no memory leak :
class Shoot extends MovableObject{
constructor(){
super();
this.speed = 2;
this.geometry = new THREE.CircleGeometry(0.5);
this.material = new THREE.MeshBasicMaterial({ color: 0xffffff });
this.mesh = new THREE.Mesh(this.geometry, this.material);
}
setRotation(rotation){
this.mesh.rotation.set(rotation.x, rotation.y, rotation.z);
}
setPosition(position){
this.mesh.position.set(position.x, position.y, position.z);
}
}
Later i've got this function, listShoot is the only place I have Shoot instances :
var position;
listShoot.forEach(function(shoot, i, list){
position = shoot.getMesh().getWorldPosition();
if(/*i want to destroy my shoot*/){
list.splice(i, 1);
scene.remove(shoot.getMesh()); // This is ThreeJS
delete shoot;
console.log("shoot destroyed");
}
});