Insufficient Memory Error when launching application for second time after calling finish() in main activity..

by Streets Of Boston » Tue, 21 Apr 2009 22:21:19 GMT


Sponsored Links
 Do you statically cache objects?
If your activity is gone/finished, that does not necessarily mean that
your game's process has died. Static references/caches may still be
active.




--~--~---------~--~----~------------~-------~--~----~



Insufficient Memory Error when launching application for second time after calling finish() in main activity..

by quakeboy » Wed, 22 Apr 2009 20:48:38 GMT


 Thnx for replying SOB..
I found I was using all Animation objects like that and I changed it.

Later, still I found it was crashing at one particular line.. It might
be helpful for developers so here it is..

==========BEFORE===============

I set a different background at runtime.. like this.. (Its a 320 x 480
image)
view.setBackgroundResource(R.id.mybgid);

===========NOW==============

Now I removed that line and do this..
Bitmap lastbg = null; (this is on top only)

if (lastbg != null) lastbg.recycle();
Bitmap b = BitmapFactory.DecodeResource(.....as req.....);
BitmapDrawable bd = new BitmapDrawable(b);
view.setBackgroundDrawable(bd);



Now the final result..
My application still crashes, but the crash frequency has reduced to
25%

Now I am sorry, but Some Android Engineers from Google were stubborn
telling that BitmapFactory and settings image resources never leak
memory..

But in my personal experience, I found When I load sprites for each
level, initially after the level is over, I did not recycle() and then
it crashed frequently.. later I did that at the end of each level and
crash frequency dropped a lottt..

I even tried System.gc() in lot of places... Guys have to understand..
we use JAVA !!! not C++... we dont have delete operators.. or free
()... how the, am I supposed clear memory... Please GC better for
images..

Moreover through my application I have a lot of imageview for which I
change their Image on touch event ACTION_DOWN like this...

imgbtn.setImageResource(R.drawable.mouse_down_sprite);

Does all this leak little amounts of memory ??
Can someone tell me how to change this discussions subject ?





--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Insufficient Memory Error when launching application for second time after calling finish() in main activity..

by quakeboy » Wed, 29 Apr 2009 20:51:58 GMT


 Hey i found a lot of help with this article
 http://android-developers.blogspot.com/2009/01/avoiding-memory-leaks.html 

Hope it helps others too





--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. When is an app movable to sd card?

Hi,
what do I have to do in order for my app to be "movable to sdcard"?
App2SD for example lists my app as not movable.


Thanks and greetings from Zurich,
Stephan

-- 

2. how to fetch the facebook friend list

Hi
  I am new in android. In my android application i have one button if
user click that then i need to display the friend list of the facebook
user.

  i dont know how to do this, plz give me any idea

Thanks
C.Rajesh

-- 

3. How to give path..?

4. Nexus S with soju-userdebug 2.3 GRH55 79397 test-keys / will not update to 2.3.1 GRH78

5. How can we give path..?

6. 3D Maps for Android

7. Sold ( wts zte blade )