I have this application that, once I go through, there is approximately 4mb that gets added once redirected to the home page(home activity).
I have bitmaps and I do release them, I nullify all member variables at the onDestroy. I have used the GC in the android studio but it does not come back to around the same memory size of the first time that activity was called.
The process of my application is :
Login -> Home -> Image Capture -> Summary (click done at this point to return to Home)
Doing so add's approximately 4mb every run of this flow in the android monitor when you are back to the Home activity.
Is this normal, am I missing something? I have tried with leakcanary but I have not received anything from it(and yes I know its setup because I get the initial access request).
I think this is ridiculous because someone can use this application for 10times or maybe 20 000 times before resetting it and 20 000x 4mb that is way too big.
While LeakCanary can be useful to find some memory leaks, I've found that Android Studio's tools are better (in my humble experience). I recommend you use the Android Studio's HPROF Analyzer to try and find your leak.
Go to the Memory Monitor do the chain of events that cause a leak and then click the Dump Java Heap button. After it's done it should automatically open your dumped heap snapshot. There, on the top right you should see the Analyzer Tasks tab, click it and run a memory leak detection.
Unfortunately without some code to look at this is the best advice I can give you.
Related
I am in desperate search of a memory leak and I was wondering how to read my memory heap dump:
Does that for example mean, that MainActivity is active twice? Or only that it's in the backstack twice?
Why would my TrackingService be called twice? It gets activated at startup and then basically forgotten by the rest of the app.
What's up with ChooseLoginRegistrationActivity? Is it in the backstack 3 or 5 times? What are the two weird Lambda activity? ChooseLoginRegistrationActivity is always finished with finish() after a ´startActivity()`, should it even pop up here at all?
When I call finish() on an activity, will the memory allocated to that activity be freed up with the next iteration of the garbage collector? Because when I call the gc manually in the profiler, the memory wasn't released, and waiting didn't help either. Going to the desktop of my smartphone released like 50% of my apps memory, and going back to the app didn't claim the memory back.
A bit late, but you may find using Eclipse MAT useful. You can create a heap dump from Android Studio Profiler and convert it into standard .hprof in order to import it into Eclipse MAT.
In Android\Sdk\platform-tools (to have access to the hprof-conv tool available that converts the dump), open a terminal and type the command
hprof-conv AS-name.hprof EclipseMAT-name.hprof
This will generate a converted file with your given EclipseMAT-name name which you can use to import a proper standard heap dump into Eclipse MAT.
After importing into MAT you can see an overview of your memory at the given heap and can even get custom reports for Leak Suspects which may bring you closer to the culprits of those terrifying OOM errors.
LeakCanary can also prove useful for finding these pesky errors.
Hope this might help you and anyone else with finding memory errors.
I want to optimize my Xamarin.Forms app, so I am starting to use Xamarin Profiler, and I can see that the initial memory allocated in my Android app is always around 50MB.
The allocated memory is 50MB when the app starts, and it starts to increase around +1.6MB when I do push and around +0.2MB when I pull a page.
Of course, the more I navigate, the app goes slower and slower.
But I don't know if this amount is OK or if the app is consuming too much memory.
Guys, could you orient me a bit more about this? I am using MVVMCross (as MVVM framework) and I am not showing images in the MainPage.
Allocating +1.6MB when navigate to page is normal. But it should be released after navigating back and GC calling.
If you are not caching the pages all memory should be released and you should not see 0.2MB added after pulling a page, so I think you do have a memory leaks. Making memory snapshots and comparing between them can help you to detect memory leaks.
To check where memory leaks could be do the next steps:
Because Profiler manual snapshot is not working in latest (0.32) version set Auto Snapshot in Tools -> Options -> SnapShots. I recommend to set it to GC option.
Make snapshot (call GC if you set autosnapshot to GC option)
Navigate to Page you want to check memory leak.
Navigate back
Make snapshot again,
Compare between two snapshots and check what wasn't released
Try this link for more info.
I hope this post is helpful for you.
I was looking at the memory usage in android studio and noticed that every time I launch my app, the memory increases by a few MB. I've never got a OutOfMemory exception crash report from any of my supported devices. I'm not familiar with a lot of the tools included in the android sdk so I'm not sure if this signifies a memory leak or not.
In the android studio memory monitor, this is what the graph looks like after 3 launches:
As you can see, the memory increases a few MB each launch.
Does this mean I have a memory leak?
If so what steps can I take to find the source of the memory leaks?
To make sure your app doesn't have memory leaks you need to do two things:
Make a heap dump.
Analyze it with some memory analyzer.
The way to obtain a heap dump is described in the official documentation.
Once you have your dump, you can load it into the memory analyzer tool (I prefer YourKit, but you can pick up any analyzer you like) and look for leaked objects (the steps to do it can be found in the documentation of chosen memory analyzer).
Simple YourKit workflow: start the analyzer, open the heap dump via Ctrl + O. You'll see the screen similar to attached below:
Click the Inspections button on the left side and then Alt + A (or Run All button). The inspection you're interested in is Objects retained by inner class back references contained within Possible leaks group. Here I have only String objects, which can be considered normal. Any time you see here some of your own classes, you have a memory leak. You can click on your objects (if you have them listed here) to see which references it has and who references it to understand what's the leak source.
I am creating an app that works on large images and data caching.
I am using a top end model phone which I believe can handle memory issues better than other phones.
Just want to make sure that it can also perform on other phones.
Is there any tool or application in eclipse or separate that can monitor memory usage.
Will be great If I can see the heap size; whether data is garbage collected instantly after activity finishes; etc.
Thanks
Mostly what you're looking for is the Heap and Allocation Tracker in the DDMS. In Eclipse, you can open the DDMS perspective by clicking Window->Open Perspective->Other...->DDMS.
Once in the perspective, you can click on the device you want to track, find the app you want to track in the Devices tab. Click the Update Heap button (it's a green cylinder icon), and the Heap tab on the right will open. The Allocation Track also in that perspective can be used to track object allocations.
Aside from that there is also the Eclipse Memory Analyzer tool which may come in handy.
DDMS documentation.
Related answer.
Noob question!
My whiteboard/drawing app runs fine, using a combination of simple image views and bitmaps with me rendering a path to a bitmap and copying over as needed. I have it multitasking on my ICS Transformer without problems. However, if I exit the app with the Back button and then run it again, it fails; I get a memory error on the second run when I try to draw something.
Out of memory on a 4096016-byte allocation
Although sometimes I don't get that and it runs a second consecutive time. When I run it a third time, it works, and the fourth, again it Out-of-memory's.
What manual cleanup do I have to do when an Android app exits? Should I remove all created objects and bitmaps and paths and listeners and stuff?
Looks like you have a memory leak. Make sure you follow recommendations provided here. Often Memory Analyzer Tool is very useful in such cases. Here is a video how to use it.