ros3djs
ros3djs copied to clipboard
Memory growth due to Marker object calling update function
Description When the Marker object calls the update function, the THREE.Mesh instance(color meterial) memory is not released.
- Library Version: latest (develop branch)
- ROS Version: Noetic
- Platform / OS: Ubuntu 20.04
Steps To Reproduce
...
case ROS3D.MARKER_TEXT_VIEW_FACING:
this.traverse (function (child){
if (child instanceof THREE.Mesh) {
child.material = colorMaterial;
}
});
break;
case ROS3D.MARKER_MESH_RESOURCE:
var meshColorMaterial = null;
if(message.color.r !== 0 || message.color.g !== 0 ||
message.color.b !== 0 || message.color.a !== 0) {
meshColorMaterial = this.colorMaterial;
}
this.traverse (function (child){
if (child instanceof THREE.Mesh) {
child.material = meshColorMaterial;
}
});
break;
...
Expected Behavior Open Chrome developer tool and click Memory tag, memory stable
Actual Behavior Memory is growing
Quick fix
...
case ROS3D.MARKER_TEXT_VIEW_FACING:
this.traverse (function (child){
if (child instanceof THREE.Mesh) {
child.material.dispose();
child.material = colorMaterial;
}
});
break;
case ROS3D.MARKER_MESH_RESOURCE:
var meshColorMaterial = null;
if(message.color.r !== 0 || message.color.g !== 0 ||
message.color.b !== 0 || message.color.a !== 0) {
meshColorMaterial = this.colorMaterial;
}
this.traverse (function (child){
if (child instanceof THREE.Mesh) {
if (child.material !== null) {
child.material.dispose();
}
child.material = meshColorMaterial;
}
});
break;
...
@Naxior I am not able to test it right now. But could you create a PR in the meantime? You found the bug, so it is better, when you write the commit.