dispose method

  1. @mustCallSuper
void dispose()

Release any resources held by this render object.

The object that creates a RenderObject is in charge of disposing it. If this render object has created any children directly, it must dispose of those children in this method as well. It must not dispose of any children that were created by some other object, such as a RenderObjectElement. Those children will be disposed when that element unmounts, which may be delayed if the element is moved to another part of the tree.

Implementations of this method must end with a call to the inherited method, as in super.dispose().

The object is no longer usable after calling dispose.

Implementation

@mustCallSuper
void dispose() {
  assert(!_debugDisposed);
  if (kFlutterMemoryAllocationsEnabled) {
    FlutterMemoryAllocations.instance.dispatchObjectDisposed(object: this);
  }
  _layerHandle.layer = null;
  assert(() {
    // TODO(dnfield): Enable this assert once clients have had a chance to
    // migrate.
    // visitChildren((RenderObject child) {
    //   assert(
    //     child.debugDisposed!,
    //     '${child.runtimeType} (child of $runtimeType) must be disposed before calling super.dispose().',
    //   );
    // });
    _debugDisposed = true;
    return true;
  }());
}