Sarath Kumar
Sarath Kumar

Reputation: 204

How to clear heap memory in flutter web?

Im working on flutter web.I need to know how to clear heap memory in flutter web. I have used simple text widget but it takes 144mb as heap. I dont know where from it comes. My code:

import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    title: 'Demo',
    home: Text('hi'),
  ));
}

I have attached pictures for referenceenter image description here

enter image description here

kindly tell me how to clear this memory.

Upvotes: 1

Views: 3145

Answers (2)

Benjamin Lee
Benjamin Lee

Reputation: 1224

If what you're asking is how to run flutter on web such that it consumes less memory at the outset, the answer may be to run it in release mode using the html renderer rather than the canvas renderer. (More on renderers: https://flutter.dev/docs/development/tools/web-renderers)

flutter run -d chrome --web-renderer html --release

This worked for me. Running a simple hello world app, my heap was measuring ~150mb even in release mode. Then, I switched to html renderer. Now, in debug mode the heap is ~60mb. In release mode it's ~7mb.

Upvotes: 1

Alex Radzishevsky
Alex Radzishevsky

Reputation: 3768

Two points here:

  1. My assumption is that you are running application in debug mode. In debug mode application includes a lot of things for debugging purposes that will not be included in your release app. For instance, application that I am working on on start with log in screen takes ~100Mb in debug mode, while it takes only ~20Mb in release mode. So try to compile your app in release mode and see.

  2. I do not think you can clear memory. Dart has GC (garbage collector) that does it for you. All you need to do as developer is to make sure you do not have objects that can not be garbage collected and thus remain in heap of VM causing memory leak over time.

Upvotes: 0

Related Questions