dispose method

void dispose()
override

Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.

Implementation

void dispose() {
  if(disposed) return;
  disposed = true;

  dispatchEvent(Event(type: "dispose"));

  if(attributes.isNotEmpty){
    for(final temp in attributes.keys){
      (attributes[temp] as BaseBufferAttribute?)?.dispose();
    }
  }

  if(morphAttributes.isNotEmpty){
    for(final temp in morphAttributes.keys){
      morphAttributes[temp]?.forEach((bn){
        (bn as BufferAttribute?)?.dispose();
      });
    }
  }

  if(userData.isNotEmpty){
    for(final temp in userData.keys){
      if(userData[temp] is BaseBufferAttribute){
        userData[temp].dispose();
      }
    }
  }

  index?.dispose();
  directGeometry?.dispose();
  attributes.clear();
  morphTargets?.clear();
  userData.clear();

  drawRange.clear();
  groups.clear();
  index?.dispose();
  directGeometry?.dispose();
  colors?.clear();
  lineDistances?.clear();
  parameters?.clear();
}