memory/ ram app issues - android

My app is a quiz that has an imageview that switches images (20) based on the question and each image is a 720*540 jpeg referenced from drawable resource. I also have a gallery of all the images that the user can scroll between. I have noticed that my app must be using alot of ram because after closing my app and using other apps on my phone my launcher, htc sense, almost always crashes. I don't have this issue if my app isnt installed or used. I know android kills low priority apps to free up ram so I am guessing that my app is using so much ram that my launcher keeps getting killed. Is there a way to clear the ram my app is using when it closes? or something I should be doing such as deleting the images from memory after they are used? I am rather new to android development and still learning everything.

This is most likely either a memory leak or that you are not properly handling your images. Please look into using a library like https://github.com/nostra13/Android-Universal-Image-Loader which will ensure that your app is scaling down images for display

Related

App Memory Consumption

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

After how much memory consumption Android throws OutOfMemoryException

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 :)

strange behavior of android application

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.

Massive storage on android devices

I am using Icenium to build an application using map services, localisation services and more. I just realised that android-devices stores massive ammounts of pictures in the phones image-gallery. The application is build to look good on any device, therefore, all icons (and some images) come in 4 different sizes (high definition, low definition etc).
So when I start the application on a android-device, the image gallery instantly gets ALL the images that can be used with the app (around 600 small icons + some images).
This is a huge problem, and I havent really found a way to solve this. Is it a built in "feature" of icenium or is it a bug?
edit* Images/icons are fetched from a server at launch, so we do not want them to store locally..
Thanks!
//Joakim
As per the Icenium guys (check out this forum http://www.icenium.com/resources/forums/android-devices-/app-icons-and-images-displayed-in-gallery#a8qHkcQkbkiGelukQjTr6g), this is only true when your application is build in Debug, because in this case your app is on the SD card. Once the application is built in Release you should not see the app images in the gallery as it would be sandboxed (not on SD).

Why does an empty Android ICS app almost occupy all the heap size?

I am developing a game application under Android built for SDKs >= 8. I always tested it under an Android 2.2 phone and never had a problem. When I moved to a Nexus phone with ICS mounted on I started having problems with the heap memory allocation. I tried to remove everything in the app to see where I was having memory leak problems or strange allocations (using both DDMS and MAT under Eclipse) until I decided to just start an empty activity and to do nothing more.
Under Android 2.2 the heap size at startup is about 2.0MB, while under Android 4.1 is about 11MB. Why is there such a great difference?
More, when I play my app the heap size on ICS, the garbage collector quickly starts freeing memory and the whole application becomes slow and with a very low FPS. Under Android 2.2 everything is really smooth and clean, without any single problem.
Does anyone can suggest me where's the difference between these two systems? I don't want to talk about my app implementation (I already spent 2 weeks optimizing code, memory allocation and retention and everything else. Can't do much more), but I want to understand where all that memory goes just at app startup. Also, ICS seems to require much more memory to load and retain bitmaps and drawables.
Okay, I may be late to the party, but I figured out the root of your (and my) problem.
Before Android 3.0 (not sure if this was in the entire 1.x/2.x series) all bitmap related memory was not stored on the heap. So with 3.0 they started locating everything on the heap. I am not sure why an empty application takes up 11MB, I can only guess it is related to the default Android bitmaps used in applications.
Now there is another problem: in earlier versions of Android, there was only a 'drawable' folder, not a 'drawable-hdpi', 'drawable-mdpi' etc... folder. For some reason, when loading in a image from the 'drawable' folder, it takes up HUGE amounts of space. The solution is to add different resolution variants of your images to all the drawable-Xdpi (where X is l,m,h or xh) folders. It reduced my starting heap size from around 26MB to a good 16MB. Even if you don't resize them, and just copy-paste them into the folders, it will still result in quite a significant change in Bitmap sizes.
I hope I help some people by posting this.
-Z

Categories

Resources