Menu

Five memory leaks that kill Flutter apps on older phones
📰

Five memory leaks that kill Flutter apps on older phones

DEV Community: dart·Stacklyn Labs·about 10 hours ago
#sjmUFwmw
#devtodart#devto#dev#dispose#screen
Reading 0:00
15s threshold

A memory leak happens when your app holds on to objects it no longer needs, so the Dart garbage collector can't free them.

On a modern phone with 8 GB of RAM, a leak can hide for a while. On an older phone with 2 or 3 GB, it's a different story: the operating system kills your app in the background, or it crashes while someone is using it. Your crash reports fill up with devices you never tested on.

The most common Flutter leaks have one thing in common: something outlives its screen .

1-3. Controllers you never disposed

AnimationController , TextEditingController and ScrollController all hold resources. If you create one in a State , you dispose it in that State .

class _ProfileFormState extends State < ProfileForm > with SingleTickerProviderStateMixin { late final AnimationController _fade ; final _email = TextEditingController (); final _scroll = ScrollController ();

@override void initState () { super .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.