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. alignment issue in top left and top right

i am trying to align my two image buttons (back and next) at the top
of an image background and trying like below xml code.But both the
images are overlapping on top left corner.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/
android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
        android:gravity="center_horizontal"
        android:background="@drawable/image_wo_lbl_0"
    >
   <ImageView
   android:id="@+id/back"
   android:src="@drawable/btn_back"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentLeft="true"
   />
   <ImageView
   android:id="@+id/next"
   android:src="@drawable/btn_next"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentRight="true"
   />

</FrameLayout>

Thanks!!

-- 

2. Spica - CyanogenMod-6.1.0-RC1-Spica-alpha7.

Ada updetan baru! Highlight: Compass is working! :D

Silakan ke TKP:
http://forum.samdroid.net/f53/cyanogenmod-6-1-0-rc1-spica-alpha7-3-a-3138/

Sent from my Mnk Powered by urah tmpaaat!

-- 
===============
"Indonesian Android Community [id-android]"

PING'S mobile
Email: sa...@pings-mobile.com  Ph. (021) 96087100
---------------------
Yopie Ratjoen
Email: yo...@ratjoen.com  Ph. 08977726681
--------------------
Gila original
Email: i...@gilaoriginal.com  Ph. (031) 91555898
--------------------

Aturan Jual/Kloteran ID-Android  http://goo.gl/azW7

3. acer liquid

4. not well-formed invalid token parser.pm

5. Best tool to visualize an Android Project ?

6. How to change the name of an app in the application menu?

7. Read Barcode