2

My project is totally bases on images. I am using a gallery and a coverflow in my project and due to less heap size the app is forcefully close.

So every time I load my app I want to clear heap size, so I can reuse it.
I have used System.gc() & recycle () method in gallery and coverflow, but my gallery and coverflow, are inter-related so the object is always referenced, so System.gc() and recycle() are not having effect and my gallery and coverflow still crashes at a random point of time while using it.

For some reason I can't show my code here and even if, it is very big so I can't manage to show here.

Please help me out & thanks for reading this question.

Nickolaus
  • 4,785
  • 4
  • 38
  • 60
unkown
  • 1,100
  • 5
  • 18
  • 39

3 Answers3

0

Well, You don't have any real control over forcing the GC to run. It runs on it's own, whenever it thinks it's time.

When does System.gc() do anything

So, the only option that you have is to judiciously use images and bitmaps.

Hint => Use soft references. http://developer.android.com/reference/java/lang/ref/SoftReference.html

Community
  • 1
  • 1
Kumar Bibek
  • 9,016
  • 2
  • 39
  • 68
  • how to use it with gallery and coverflow – unkown Apr 17 '12 at 07:16
  • You will have to search for a working sample. You will find some on the internet. First, try to understand the concept, and then, it will be more clear how to use it. – Kumar Bibek Apr 17 '12 at 11:14
0

To control the crash due to this memory issue, you need to do like this:

BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap preview_bitmap=BitmapFactory.decodeStream(is,null,options);

The inSampleSize value reduces the memory consumption.

More information can be had from this thread:

Strange out of memory issue while loading an image to a Bitmap object

Hope this will help you.

Community
  • 1
  • 1
UVM
  • 9,776
  • 6
  • 41
  • 66
0

Increase the heap space.. and turn on auto delete, like in eclipse if you go to preferences and manage the heap space; you can click the trash button there

Daksh Shah
  • 2,997
  • 6
  • 37
  • 71