I have been playing with optimizing my app, and I see that there are some general ideas on how much memory it should use... I'm running between 70-80Mb right now, is that a crazy number or just a little on the heavy side?
My second question is about the memory I am using. About 42Mb is taken up by graphics, whether I run the app with the layout graphics or run it without setting any views... any ideas on where to look? I feel like it is the theme, but I am not sure how to test that.
I've been searching for days to figure out why it uses so much and cannot figure it out. It remains constant regardless of which activity I am on, any ideas are welcome!
UPDATE:
I ended up running it on an emulator and got about 26Mb, more what I was expecting, but it runs at 70Mb with the 42Mb of graphics on the actual device.
The emulator allows for a 384Mb app after getting memoryclass information, while the device only allows 256Mb... the emulator has more storage and runs more efficiently.
The emulator is Android 8.1 27api while the device is Android 7.0 24api.
Tried on an older Android 5.1.1 api 22 below also.
Any ideas?
I have another question with about why the emulators have a such a difference in performance here if you know the answer on that, but I wanted to keep these questions separate: Other Question
Android Studio has an awesome tool called Memory Profiler. It helps you analyze possible memory leaks and see which calls are using up the most memory. You can even pause the processor and 'zoom in' to deep dive on the call stack.
You can use LeakCanary A memory leak detection library for Android and Java. Maintain by Square. This is one of the best developer's Tool for memory optimization and detecting leaks.here
Related
I have tried looking at this SO post but I already have 16GB of RAM and I don't want to decrease AVD memory. I do not understand why the Android Emulator takes up so many resources (%25+ CPU, Almost 1GB of RAM) when running a simple app (Like this: Single Activity with a RecyclerView and its Adapter. That's it). Any help would be appreciated.
My fan is always on when using the Android Emulator in Android Studio.
This is normal for the Android Emulator. My numbers are the same.
This is a big pain for me and even bigger after upgrading the AndroidStudio version.
One alternative is to use an external Device for Debugging in place of an Emulator.
Its an old post, but still in most of the places i found out that an android app gets around 16-32 MB memory
But when i check android Profiler, it says that my app is currently using around 350 MB memory on Samsung Galaxy S7.
I get OutOfMemoryException on my app a couple of times, I was curious why its happening. When i dig down a little i found out about 16-32 MB limit, but in actual my app is using 350 MB
I want to know how much memory a normal android phone gives to each app, or is it a variable number, and if no app is running android will not give outOfMemoryException, and if so many apps are in stack then there is a higher chance of OutOfMemoryException
But again there will be some limits.
Android devices vary significantly now that the OS is getting older. You should definitely aim for under 32mb limit if you want your app to work on lower end devices to be safe. Unless you are loading some very large images it sounds like your code is leaking memory.
Start by removing any image (or other asset) loading from your app to see if you still have problems.
If you do, check out LeakCanary, and when you find the leaks learn about them and why they are happening because it will help you immeasurably to become a better Android programmer. One of the chief ways apps leak memory is by passing an Activity context to a long running task :)
I read articles about profiling and tried it in Android studio 3.0.
But I'm still curious about next:
1) how can I find, which activities and fragments are storing in memory now?
2) which memory size are they consuming at the moment?
3) maybe more detailed memory consumption (by objects)?
I only started an investigation about profiling and app performance, please help with it or show good articles (with examples in the latest Android studio version).
As a first question my app now consumes 90Mb of memory. When I dump java heap, I see next (btw, are those numbers in bits?):
But I really cannot understand, which of that numbers relates to my objects/activities etc.
Thanks in advance!
I have developed an app which uses appcompat theme as the main theme.
In some activities there are more than 300 lines of code which use several card views, and in them are spinners and edit texts.
It performs well in many phones, but in phones with low RAM it hangs and causes the memory to be freed
I've used asynctask but the InBackground method is worker and doesn't interfere with graphics.
How can I handle this?
There is really good documentation on this issue on the Android Developer website: http://developer.android.com/training/articles/memory.html
Please post code if there is a specific area that you are concerned with.
When programming to mobile we need to face this kind of challenge. You should specify a target when you start to develop. In other words, it is really hard to develop an app which has the same and perfect behavior in all devices.
Brotip: Try to break your code. Is not usual to have more than 300 line of code in one file. Your method probably can be optimized. Otherwise, there is nothing you can do, once you reach the physical limitation of RAM size you will face this problem.
A solution for this problem COULD be use a Local DB and store the information that you use in this activity. Then you read it little by little.
Hope it helps and give you some ideas.
I'm developing a large project with android technology
sometimes I have some exceptions like (Out Of Memory Error) on small devices
what I do when an exception occurred is to re-open the application
what happen that it leaves the previous process open and open a new process with new instance of application
I have tried to make
finish()
kill process
System.exit
to close the application and re-open it again but nothing works for me
any help please ???
First Thing you have to take care of, is Heap size.. You can track How much memory is getting consumed when your are running application. Under DDMS perspective there is a heap tab which will give you info about how much memory is consumed when you are running your application.
on what version of the android you are testing ? Android Os will allocate some memory for each application to run.In android 2.2 16mb will be allocated for one application. Version 2.3 allocates 24Mb for an application ,Android 3.0 allocates 42Mb. try testing on different versions of android, you will get to know..
Out of memory happens when RAM in a device is utilized fully, the system will throw this error and kill/restart the process. You need to find the appropriate place where you use the most of memory and handle the memory properly. Out of Memory generally happens because of poor bitmap/image handling. Check your code where you handle Bitmaps/ImageViews/PNG's etc.
Android default heap size is almost good for every heavy load jobs. Trace your code and find memory consuming parts of your code and try to optimize them. To do so, use HEAP tab in DDMS view in Eclipse.
yes that is the problem .i have faced similar problem recently then i resized my images then my problem is solved.Try to find out a way how to reduce the size of the images which you are loading from sever side back-end.