Repository navigation
Description
Steps to reproduce
- Make a new windows app, turn on Impeller in
windows/runner/main.cpp:project.set_impeller_switch(flutter::ImpellerSwitch::Enabled);
- Add
flutter_gpu(sdk) andvector_mathto pubspec, put the code below inlib/main.dart flutter build windows --profile- Run the exe with flutter gpu on:
FLUTTER_ENGINE_SWITCHES=1 FLUTTER_ENGINE_SWITCH_1=enable-flutter-gpu ./build/windows/x64/runner/Profile/<app>.exe - Watch the console
Expected results
The surface only needs 2 or 3 textures for this (the docs say it reuses a texture when Flutter is done with it), so I expected debugBackingTextureCount to stay around 2-3.
Actual results
It makes a new texture on every frame until the GC runs, then it stays at that number forever. I get 60 after 60 frames and then 62 for the rest of the run, and it never goes down. That's 62 textures for a 512x512 surface.
In my real app (bigger surface, 60 fps) I got 48, 87 and 54 in 3 runs, so it's 140-250 MB of textures that never get freed. The number changes between runs, I guess it depends on when the GC happens.
I looked at the engine code a bit. Surface::IsReusable in lib/gpu/surface.cc only reuses a texture when texture.use_count() <= 3, but the Texture, RenderPass and CommandBuffer I create each frame keep a ref to it until Dart finalizes them (the command buffer even keeps its encodables_ after submit). There's no way to dispose them from Dart, so they just sit there until GC. And PruneTextureRecords only drops textures when the size changes, so the pool never gets smaller.
I think this is kind of the same root problem as #191867 (no way to dispose gpu objects).
For now I made my own ring of 3 textures and show them with Texture.asImage(), and that stays at 3.
Code sample
Code sample
import 'dart:ui' as ui;
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_gpu/gpu.dart' as gpu;
import 'package:vector_math/vector_math.dart' as vm;
void main() {
runApp(const Directionality(textDirection: TextDirection.ltr, child: Repro()));
}
class Repro extends StatefulWidget {
const Repro({super.key});
@override
State<Repro> createState() => _ReproState();
}
class _ReproState extends State<Repro> with SingleTickerProviderStateMixin {
final gpu.GpuImageSurface surface = gpu.gpuContext.createImageSurface(512, 512);
late final Ticker ticker = createTicker(onTick);
ui.Image? image;
int frames = 0;
@override
void initState() {
super.initState();
ticker.start();
}
void onTick(Duration elapsed) {
final frame = surface.acquireNextFrame();
final commandBuffer = gpu.gpuContext.createCommandBuffer();
final t = (frames % 120) / 120.0;
commandBuffer.createRenderPass(
gpu.RenderTarget.singleColor(
gpu.ColorAttachment(
texture: frame.colorTexture,
loadAction: gpu.LoadAction.clear,
clearValue: vm.Vector4(t, 0.3, 1.0 - t, 1.0),
),
),
);
frame.present(commandBuffer);
commandBuffer.submit();
frames++;
if (frames % 60 == 0) {
debugPrint('frame $frames: debugBackingTextureCount = ${surface.debugBackingTextureCount}');
}
final old = image;
setState(() => image = surface.currentImage);
if (old != null) {
SchedulerBinding.instance.addPostFrameCallback((_) => old.dispose());
}
}
@override
void dispose() {
ticker.dispose();
image?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ColoredBox(
color: const Color(0xFF000000),
child: Column(
children: [
RawImage(image: image, width: 512, height: 512),
Text(
'frame $frames debugBackingTextureCount ${surface.debugBackingTextureCount}',
style: const TextStyle(color: Color(0xFFFFFFFF), fontSize: 20),
),
],
),
);
}
}No shaders, no draws, it only clears the texture. I dispose every image from currentImage after the next frame, so it's not the images.
Logs
Logs
[IMPORTANT:flutter/shell/platform/embedder/embedder_surface_gl_impeller.cc(126)] Using the Impeller rendering backend (OpenGLESSDF).
frame 60: debugBackingTextureCount = 60
frame 120: debugBackingTextureCount = 62
frame 180: debugBackingTextureCount = 62
frame 240: debugBackingTextureCount = 62
frame 300: debugBackingTextureCount = 62
frame 360: debugBackingTextureCount = 62
frame 420: debugBackingTextureCount = 62
frame 480: debugBackingTextureCount = 62
frame 540: debugBackingTextureCount = 62
frame 600: debugBackingTextureCount = 62
frame 660: debugBackingTextureCount = 62
frame 720: debugBackingTextureCount = 62
frame 780: debugBackingTextureCount = 62
frame 840: debugBackingTextureCount = 62
frame 900: debugBackingTextureCount = 62
frame 960: debugBackingTextureCount = 62
frame 1020: debugBackingTextureCount = 62
frame 1080: debugBackingTextureCount = 62Same numbers on a second run.
Flutter Doctor output
Doctor output
Flutter 3.47.0 • channel [user-branch] (3.47.0 tag checkout) • https://github.com/flutter/flutter.git
Framework • revision 4cf2416426 • 2026-08-11
Engine • revision 5f77625673
Tools • Dart 3.13.0 • DevTools 2.60.0
Windows 11 Pro (10.0.26200)
GPU: NVIDIA GeForce RTX 3050 Laptop GPU + Intel UHD Graphics
Impeller OpenGLES (ANGLE), profile buildMetadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fields🤔 Needs Triage
Activity
saurabh-mirajkar commentedon Oct 5, 2026
Thanks for the report. I was able to reproduce on macOS with Flutter master using Impeller Metal. Routing this to the FlutterGPU team for further investigation.
master
logs