-
Notifications
You must be signed in to change notification settings - Fork 28.9k
Memory test on scrolling large images quickly #46184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For flutter#19558 This test reveals the issue that Flutter currently retains as much as 200MB memory after scrolling. (200MB can further grow if we scroll more times). There should be plenty of time for the GC to clean such memory.
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Now we can finally reproduce the issue
b21cd67
to
fba51a9
Compare
class DummyImage extends StatelessWidget { | ||
DummyImage(this.index) : super(key: ValueKey<int>(index)); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final Future<ByteData> pngData = _getPngData(context); | ||
|
||
return FutureBuilder<ByteData>( | ||
future: pngData, | ||
builder: (BuildContext context, AsyncSnapshot<ByteData> snapshot) { | ||
return snapshot.data == null | ||
? Container() | ||
: Image.memory(snapshot.data.buffer.asUint8List()); | ||
}, | ||
); | ||
} | ||
|
||
final int index; | ||
|
||
Future<ByteData> _getPngData(BuildContext context) async { | ||
return DefaultAssetBundle.of(context).load('assets/999x1000.png'); | ||
} | ||
} | ||
|
||
class ImagePainter extends CustomPainter { | ||
ImagePainter(this.image); | ||
|
||
@override | ||
void paint(Canvas canvas, Size size) { | ||
canvas.drawImage(image, Offset.zero, Paint()); | ||
} | ||
|
||
@override | ||
bool shouldRepaint(CustomPainter oldDelegate) { | ||
return false; | ||
} | ||
|
||
final ui.Image image; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a comment explaiing why we've done this as opposed to Image.asset would be helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
And remove the unused class.
979b432
to
64395d4
Compare
For #19558
This test reveals the issue that Flutter currently retains as much as
500MB memory after scrolling. (500MB can further grow if we scroll more
times). There should be plenty of time for the GC to clean such memory.
We've identified the issue to be in the IO thread: #19558 (comment)