Windows: closeTexture hands the texture to UnregisterTexture's callback and
frees its frame buffers there; frames pushed after close are dropped. Without
"recycle" the object is kept for the process lifetime (the session may still
hold its pointer); an engine that shuts down keeps its open textures the same
way. A duplicate createTexture key gets -1, getTexturePtr of an unknown key 0.
macOS: closeTexture drops the frame and closes the texture to later frames;
only "recycle" removes it from the plugin.
Linux: the frame handed to the engine last is freed at that engine's next
copy_pixels or once the engine has shut down, not at close: from Flutter 3.32
the raster thread can still be uploading it.
Tests: windows/test/run_tests.sh (plain, --asan, --tsan) and
linux/test/run_tests.sh (plain, --asan).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each session created a new TextureRgba and closeTexture never released it, so
the engine's FlPixelBufferTexture kept its GL texture (one frame of GPU or,
with llvmpipe, process memory per session). Releasing the object is not safe:
FlPixelBufferTexture deletes its GL texture in dispose without selecting a GL
context, so a release from another window deletes that window's texture of
the same name (upstream PR #2 turned the remaining window white).
closeTexture(key, recycle: true) now keeps the texture in a list of the
plugin instance, i.e. of the engine (window) that created it, and the next
createTexture of that engine registers it again. Its GL texture is only ever
touched by that engine's populate in its own context, nothing is released,
and the GL memory is bounded by the number of textures a window had open at
once. When the engine goes away the recycled textures stay referenced for the
same reason. Without recycle (old callers, or a tab that moves to another
window while its session still holds the pointer) a closed texture stays
terminated and is never handed out again.
With no frame waiting, copy_pixels hands out one transparent pixel instead
of no buffer, so a recycled texture cannot show the last frame of its previous
session before the first new frame.
Dart: closeTexture(int key, {bool recycle = false}) sends "recycle"; other
platforms ignore it. Tests: all ten Linux lifecycle tests pass (clang and
gcc, -Wall -Werror, also under ASan/UBSan); Dart 4/4.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
closeTexture marked the texture terminated but kept the frame last handed to
the engine and any frame still waiting, and TextureRgba had no finalize, so
each closed session kept one or two frame-sized buffers forever (2 x
width x height x 4 bytes measured per 1080p session).
terminate now frees both buffers under the texture mutex: the texture is
already unregistered and OnRgba stops copying once terminated is set. A
finalize frees them as well. GObject and GL lifetime are unchanged here.
Tests: close_frees_frame_buffers, closed_texture_ignores_late_frames,
finalize_frees_frame_buffers and frames_racing_close pass (also under ASan);
the four recycling tests still fail.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>