ros3djs icon indicating copy to clipboard operation
ros3djs copied to clipboard

Memory growth due to Marker object calling update function

Open Naxior opened this issue 3 years ago • 1 comments

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 avatar Oct 28 '22 10:10 Naxior

@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.

MatthijsBurgh avatar Oct 28 '22 13:10 MatthijsBurgh