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 reference
kindly tell me how to clear this memory.
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.
Two points here:
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.
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.
Related
I am getting aw snap or sometimes not enough memory problem when I reload my WebGL page. I have a WebGL project which is empty (just a camera + light), developed in unity3d. I am reloading it, and profile its memory.
As you can see that its load 1.2MB in the first load than 1281 MB in second then 1574 then 2160 and then get crash. I am amazed that why it is happening?
I searched and found that
One of Unity fellows told that when browser Dev Tool is open, each page reload will increment the memory:
"
One point to note is that when profiling memory usage on page reloads
in Firefox, make sure to have the Firefox web console (and debugger)
window closed. Firefox has a behavior that if web console is open, it
keeps the Firefox JS debugger alive, which pins all visited pages to
be cached in memory, never reclaiming them. Closing the Firefox web
page console allows freeing the old pages from memory
BUT
My testing suggests that it is true for Chrome but not for firefox. Firefox keeps increments the memory with each page reload no matter your Dev tools are open or close.
But my problem resolve in chrome (still question on firefox? I guess it the default behaviour of browser), after closing the dev tools memory is not incremented on chrome.
the problem
the webgl build runs fine on every desktop browser and firefox mobile, but crashes after 3 seconds when using chrome mobile or safari mobile with the "aw, snap" page.
the problem was the amount of RAM that the project was using for loading assets.
i found that the main problem was loading the audio system.
when the game started the RAM usage quickly escalated from 300 MB to 1,3GB.
how i fixed
i had a background music 20 minutes long, i cut that to 5 minutes.
click the music, then click override for webgl
set the load type to Streaming
set the quality to 1
with this workaround the RAM usage floats around 600 MB, this allows the build to run on mobile.
this is an example
EDIT
turns out that after ios 15.5 update everything runs fine.
I have recently started using Flutter ad noticed that apps in debug mode shows "Slow Mode",I know that it shows slow mode only in debug mode and we can remove it by setting debugShowCheckedModeBanner: false on our MaterialApp.So,The question is,my app has a Slow Mode banner/ribbon in the upper right. Why am I seeing that?
App is supposed to be relatively slower in debug mode.
Debug mode on device (including simulators, emulators):
Turns on all the assertions in the world, includes all debugging information,
enables all the debugger aids (e.g. observatory) and service
extensions. Optimizes for fast develop/run cycles. Does not optimize
for execution speed, binary size, or deployment. Used by flutter run.
Built with sky/tools/gn --android or sky/tools/gn --ios. Also
sometimes called "checked mode" or "slow mode".
I am using crosswalk to better support older android devices. But app has 5% CPU even doing nothing and even in idle state on background.
Removing crosswalk from project solves problem, but I want it to stay included because of the benefits.
I have found two things what makes the CPU.
1. animated gif image
2. bug in ionic wrapper of device motion cordova plugin (acceleration watcher never stop then)
animated gif: I had animated gif as loading spinner in my index.html while my app becomes available. On mobile phones it was not visible at all, because splash screen is turned off after app init, but it was for browser use. Removing this gif solves about 3% CPU
I have device motion plugin in my app and I was using it as described in ionic docs, so if not needed anymore I have called unsubscribe. But ionic was not calling clearWatch method correctly (with wathID parameter), so the watcher never stops. It caused another ~3% CPU. As an workaround I have used plugin directly, bypassing ionic wrapper as described in cordova docs.
Removing those two problems I get approximately 0.4% CPU which I think is the lowest minimum, because I have tested empty index.html builded into cordova app even without the crosswalk and still getting the minimum 0.4% CPU usage.
Hope that this help someone else, happy coding ;)
I recently read about the HAXM , followed the steps, for first few days emulator used to get started in less than minute but now it gets stuck at this point - as shown below.. although it shows correct time & clock remains working . The worst part is all of the emulators I create show same problem .Any solution ?
You can try couple of things here
Check the RAM size allocated for Emulator. The best RAM size recommended is around 512MB for an Emulator. Make sure you have set the appropriate RAM size
Kill all your emulators, restart your machine and create fresh AVDs
Is this happening with the same application or different ones? a little bit detail on the application will help in suggesting more work around.
a. If it is an OpenGL application choose use Host GPU on your AVD and also install the correct graphics driver on your host machine
I recently had an app rejected from the app store because of Low Memory Exception. The app doesn't leak memory, but its base memory footprint seems to be too high. According to the crash logs sent by apple, it was taking about 14000 pages in the memory (mostly due to huge textures). There were 2 strange things though:
I tested it on 5 devices rigorously before submitting, and never got this crash on any one of them.
I did optimize the textures after the rejection, and brought them to about half the original size (texture memory consumption).
I have no way of knowing how many pages my app is taking now, unless I can reproduce the same crash as apple (which I never could). Is there another way to be able to find out the memory footprint of my app, so that I can be sure that it is optimized enough now.
I did try instruments, but my app crashes when I try to run it through my XCode (must be some problem with my XCode). But it works perfectly when I run it directly on my iPhones/iPods. Any help in finding out the memory footprint of my app on iPhone (if there is something analogous to task manager of windows), would be appreciated.
Thanks
EDIT:
Launching the app from XCode gives the following error in the console:
"Error launching remote program: failed to get the task for process 553."
Launching the app with Activity Monitor gives the following error:
"Target terminated too early to collect data"
EDIT2:
I was able to run my app with Activity Monitor, by using a dev profile instead of distribution profile. But now there are several sections in the Activity Monitor - Physical Memory Used, Real Memory, Virtual Memory. Which one of these do I consider. To sum it up, I need to know which one of these causes the iPhone to throw a Low Memory exception.
XCode -> Run -> Run With Performance Tool -> Activity Monitor.
If the device is connected, Activity Monitor runs on the iPhone/iTouch.
I think you're coming at this from the wrong angle. You're asking how to find the memory footprint without using XCode. I think the question you should be asking is: why can you not use XCode? Presumably that's what you used to develop the application in the first place?
Without XCode you're pretty much flying blind. You say you halved the size of your textures, but how do you know? Does your app release any extraneous memory when it gets a low memory warning? (applicationDidReceiveMemoryWarning:)
First, have you looked at the crash logs from when you run your app from XCode? You should be able to see them in the Organiser in XCode.
I'm not sure there's a single solution to stop your app crashing with XCode. Normally when my iPhone won't allow debugging I just restart xCode and my handset and it starts working again. Restarting XCode sometimes helps. I would also try reinstalling both XCode and the iPhone SDK.