Android memory allocation
As with any Java VM, the heap memory will automatically grow to the max size. But, bitmaps are allocated outside the VM, so you don't "see" them easily in the stats. The best thing you can do is make sure you don't use large bitmaps, or scale them down using
http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html
From Eclipse you can generate a heap dump when you are on Android 1.6 or up and you can analyze the dump with Eclipse MAT.
Generally you can't control the max heap size on a real device, unless you are working with custom hardware or firmware.
There should be an article at developer.android.com on dumping the heap on 1.6, but I'm unable to find it. :(
Edit
Also, I have to mention that you can request more memory for applications by using
android:largeHeap="true"
in the manifest. But this is highly ill-adviced as most applications do not need this.
Memory allocation problems with android application
It seems you are not handling the resources (variables, image files,etc) properly, and its creating memory leaks in your application.
you can find here in this blog Written by Johan on handling the memory leaks in your application or see this SO Question.
Avoid memory leaks on Android
If the memory leaks are being generated in the c++ library then you can easily find the resource which is leaking the memory in debug mode.
After the result activity you should call the garbage collector as suggested by Grisgram and close any unused resources.
It would be good if you could provide the stack trace in the question.
Android Studio Profiler Memory Allocated N/A
I had the same issue and here's what I did to make it work. (This is effective when running on API level < 26 only)
- In Android Studio, go to the Configurations menu as shown in the image below and click on Edit Configurations.
- Select your app configuration from the menu on the left (usually called "app").
- Click on the Profiling tab.
- Check "Enable advanced profiling".
High memory allocation causes outofmemory crash
The problem here is due to the device we are using. On the Note 2 on android 4.4 Samsung introduced an issue with the GC causes the GC not to run.
Pause GC Error post android 4.4.2 upgrade
We will be downgrading our devices. We did a quick test on 4.3 wich does not crash after 3 test runs.
App Memory Usage differs between Devices
Samsung has additional layer of libraries for their custom UI on Android, which will eventually lead the app to consume more memory.
Moto devices have stock/native Android.
Your variables and objects take x memory in both devices, but your UI elements take more memory in Samsung in comparison to moto device.
examplel: If stock android uses Button class, Samsung will extend the Button class to make SamsungButton class which will have additional features (like water droplet sound on click).
Related Topics
Connecting to Wifi Using Adb Shell
How to Find the Logs on Android Studio
Listfragment Onlistitemclick Not Being Called
Differencebetween @Id and @+Id
Autoincrement Versioncode with Gradle Extra Properties
What Do Gc_For_Malloc, Gc_Explicit, and Other Gc_* Mean in Android Logcat
Android Split Action Bar with Action Items on the Top and Bottom
Camera Tutorial for Android (Using Surfaceview)
Textinputlayout Not Showing Edittext Hint Before User Focus on It
Hide Ics Back Home Task Switcher Buttons
Android: Open Activity Without Save into the Stack
How to Handle Multiple Countdown Timers in Listview
Implementing Text Watcher for Edittext
ASP.NET Web API Authentication
How to Set Text Size of Textview Dynamically for Different Screens
Android - Startactivityforresult Immediately Triggering Onactivityresult