Skip to content Skip to sidebar Skip to footer

Android Memory Leak Solution

I'm having problems with memory leaks. When I show an Activity every thing works. When I press back and try to reload the Activity I get an outOfMemoryException. So from the docs

Solution 1:

What does your application (or rather, this Activity) actually do? I don't see how that code alone could cause much harm, but I could be wrong.

I had a bit of trouble with memory leaks & memory tracking which I later fixed, these articles gave me a good bit of insight:

http://android-developers.blogspot.co.uk/2009/01/avoiding-memory-leaks.html

http://android-developers.blogspot.co.uk/2009/02/track-memory-allocations.html

A bit more info may be needed to help you though. Your Activity is called FotoGallery so I'm going to have a quick guess and say your problem lies with the pictures that you load in and whatnot. There's been quite a bit of questions on SO regarding limited memory & loading pictures.

Solution 2:

I solved this issue by adding System.gc(); in the beginning of the setImage method (without any if's or anything like that).

Post a Comment for "Android Memory Leak Solution"