dispose method

  1. @override
void dispose()
override

Releases every persistent resource this device holds — the textures and geometry buffers handed out by createTexture, createTextureFromPixels, createCubeTextureFromPixels, createCubeRenderTarget and uploadGeometry.

What "release" means is a property of the backend, not a promise this method makes uniformly. WebGL2 objects are explicitly deletable — a WebGLTexture or WebGLBuffer the driver is still holding onto is a real leak, not a GC artefact — so that backend actually calls gl.deleteTexture and friends here. flutter_gpu's Texture has no native dispose at all, so letting one go out of scope is the only release path that backend has, which makes its implementation of this method a deliberate no-op rather than an omission: there, memory returns through the collector. The software rasteriser holds nothing but Dart lists, which the garbage collector already reclaims, so its implementation is a no-op for a third, unrelated reason.

Call once, when the device is being torn down. Nothing here promises safe reuse afterwards — a disposed device's handles are no longer valid on backends that actually freed them.

Implementation

@override
void dispose() {
  _isDisposed = true;
  _live.clear();
  unawaited(_lost.close());
}