Unverified Commit 7514c16a authored by Dan Field's avatar Dan Field Committed by GitHub

Dispose precached image info (#143017)

`precacheImage` was failing to dipose the `ImageInfo` it receives. That's part of the contract of being an image listener.

I'm doing this in the frame callback for the same reason as evicting it from the cache.
parent ac5c3dec
...@@ -123,6 +123,7 @@ Future<void> precacheImage( ...@@ -123,6 +123,7 @@ Future<void> precacheImage(
// image stream. // image stream.
// See ImageCache._liveImages // See ImageCache._liveImages
SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) { SchedulerBinding.instance.addPostFrameCallback((Duration timeStamp) {
image?.dispose();
stream.removeListener(listener!); stream.removeListener(listener!);
}, debugLabel: 'precacheImage.removeListener'); }, debugLabel: 'precacheImage.removeListener');
}, },
......
...@@ -798,8 +798,6 @@ void main() { ...@@ -798,8 +798,6 @@ void main() {
}); });
testWidgets('Precache', testWidgets('Precache',
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async { (WidgetTester tester) async {
final _TestImageProvider provider = _TestImageProvider(); final _TestImageProvider provider = _TestImageProvider();
late Future<void> precache; late Future<void> precache;
...@@ -818,7 +816,10 @@ void main() { ...@@ -818,7 +816,10 @@ void main() {
// Check that a second resolve of the same image is synchronous. // Check that a second resolve of the same image is synchronous.
final ImageStream stream = provider.resolve(provider._lastResolvedConfiguration); final ImageStream stream = provider.resolve(provider._lastResolvedConfiguration);
late bool isSync; late bool isSync;
stream.addListener(ImageStreamListener((ImageInfo image, bool sync) { isSync = sync; })); stream.addListener(ImageStreamListener((ImageInfo image, bool sync) {
image.dispose();
isSync = sync;
}));
expect(isSync, isTrue); expect(isSync, isTrue);
}); });
...@@ -1565,8 +1566,6 @@ void main() { ...@@ -1565,8 +1566,6 @@ void main() {
}); });
testWidgets('precacheImage does not hold weak ref for more than a frame', testWidgets('precacheImage does not hold weak ref for more than a frame',
// TODO(polina-c): clean up leaks, https://github.com/flutter/flutter/issues/134787 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async { (WidgetTester tester) async {
imageCache.maximumSize = 0; imageCache.maximumSize = 0;
final _TestImageProvider provider = _TestImageProvider(); final _TestImageProvider provider = _TestImageProvider();
...@@ -1597,7 +1596,10 @@ void main() { ...@@ -1597,7 +1596,10 @@ void main() {
expect(provider._lastResolvedConfiguration, isNotNull); expect(provider._lastResolvedConfiguration, isNotNull);
final ImageStream stream = provider.resolve(provider._lastResolvedConfiguration); final ImageStream stream = provider.resolve(provider._lastResolvedConfiguration);
late bool isSync; late bool isSync;
final ImageStreamListener listener = ImageStreamListener((ImageInfo image, bool syncCall) { isSync = syncCall; }); final ImageStreamListener listener = ImageStreamListener((ImageInfo image, bool syncCall) {
image.dispose();
isSync = syncCall;
});
// Still have live ref because frame has not pumped yet. // Still have live ref because frame has not pumped yet.
await tester.pump(); await tester.pump();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment