dispose method

  1. @override
  2. @mustCallSuper
void dispose()
override

Called when its corresponding element disposed

Implementation

@override
@mustCallSuper
void dispose() {
  // Ensure pending layout/compositeBitsUpdate/paint render object to be finished.
  SchedulerBinding.instance!.addPostFrameCallback((_) {
    // Call dispose method of renderBoxModel when it is detached from tree.
    super.dispose();
  });

  // Clear renderObjects in list when disposed to avoid memory leak
  if (fixedChildren.isNotEmpty) {
    fixedChildren.clear();
  }

  // Dispose scroll behavior
  disposeScrollable();

  // Clear all paint layers
  _colorFilterLayer.layer = null;
  _imageFilterLayer.layer = null;
  disposeTransformLayer();
  disposeOpacityLayer();
  disposeIntersectionObserverLayer();

  // Dispose box decoration painter.
  disposePainter();
  // Evict render decoration image cache.
  renderStyle.decoration?.image?.image.evict();
}