Achieve minimum memory use in Flutter Desktop App

  Kiến thức lập trình

I’m looking to build a Flutter Desktop App that can be run in background and while in the background I want to keep it memory consumption to a minimum.

When I run a simple Demo app “Counter Incrementor” built with “flutter build windows –release” it consumes 71.3 Mb of RAM (Windows 11). If I run the same app without creating any widget:

void main() {
  hold(); //keep app running.
  //runApp(const MyApp()); // DO NOT CREATE ANY WIDGET
}

It will consume 28.7 Mb. So I assume this is a bare minimum I can get out of Flutter App.

The idea I had was to destroy the widget while the app in the background. The way I do it is as suggested here: https://api.flutter.dev/flutter/widgets/runApp.html

To artificially cause the entire widget tree to be disposed, consider calling runApp with a widget such as SizedBox.shrink.

Unfortunatly this doesn’t help at all (replaced action of the button to call a method below):

void releaseApp() {
  runApp(const SizedBox.shrink());
}

and the RAM usage jumped from 72.9 to 78 Mb. I did same test in debug mode and run GC after replacing main widget with SizedBox.shrink which didn’t help either. When looking at widget inspector I see the widget is gone however memory consumption stays the same.

Played with other various ways. Nothing helps. Any ideas and suggestions on the options how to minimize RAM usage is very approached.

New contributor

Alexey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT