dispose method

  1. @override
void dispose()
override

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

@override
void dispose() {
  _leaderLayerHandler.layer = null;
  _foregroundRenderObject?.dispose();
  _foregroundRenderObject = null;
  _backgroundRenderObject?.dispose();
  _backgroundRenderObject = null;
  _clipRectLayer.layer = null;
  _cachedBuiltInForegroundPainters?.dispose();
  _cachedBuiltInPainters?.dispose();
  _selectionStartInViewport.dispose();
  _selectionEndInViewport.dispose();
  _autocorrectHighlightPainter.dispose();
  _selectionPainter.dispose();
  _caretPainter.dispose();
  _textPainter.dispose();
  if (_disposeShowCursor) {
    _showCursor.dispose();
    _disposeShowCursor = false;
  }
  super.dispose();
}