in my onCreate (), I just use xml as a representation of the content for the activity. why am i getting a memory leak. Is this something I am doing wrong?
My xml just has 5 image buttons, with a stelstististable (selector) for each image button. each image is only 16 KB in size. (Thus, I use 10 images - the image with the pressed state and the image of the normal state for each button).
Nowhere in my work do I use LayoutInflator. Shouldn't an android recycle bimaps by itself when setting up the presentation of content from xml?
I get an error something like this:
02-17 09:18:39.797: ERROR/AndroidRuntime(372): Uncaught handler: thread main exiting due to uncaught exception 02-17 09:18:39.817: ERROR/AndroidRuntime(372): java.lang.RuntimeException: Unable to start activity ComponentInfo{***.***.*****.activity
I replaced the images, and the code worked without the application freezing, but stikll my ddms log went crazy with the following errors:
02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes 02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 270000-byte external allocation too large for this process. 02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes 02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 270000-byte external allocation too large for this process. 02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes 02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 270000-byte external allocation too large for this process. 02-17 09:18:37.287: ERROR/(372): VM won't let us allocate 270000 bytes 02-17 09:18:37.287: ERROR/dalvikvm-heap(372): 264600-byte external allocation too large for this process.
..,,,.
Although the application works, I would like to know what I am doing wrong. or is it a bug in the buggy android system?
with code:
public class VirtualHomeActivity extends Activity { ImageButton imgbtn1, imgbtn2, imgbtn3, imgbtn4, imgbtn5; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.home); } }
layout home.xml:
<?xml version="1.0" encoding="UTF-8"?> <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layoutAnimation="@anim/home_screen_animation_controller" android:background="@drawable/bg_application"> <ImageButton android:id="@+id/imgBtn1" android:layout_width="340dip" android:scaleType="fitCenter" android:layout_height="100dip" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="@drawable/custombutton1"></ImageButton> <ImageButton android:layout_below="@id/imgBtn1" android:id="@+id/imgBtn2" android:layout_width="340dip" android:scaleType="fitCenter" android:layout_height="100dip" android:layout_marginTop="5dip" android:layout_marginLeft="20dip" android:background="@drawable/custombutton2"></ImageButton> <ImageButton android:layout_below="@id/imgBtn2 android:id="@+id/imgBtn3" android:scaleType="fitCenter" android:layout_width="340dip" android:layout_height="100dip" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="@drawable/custombutton3"></ImageButton> <ImageButton android:layout_below="@id/imgBtnS3" android:id="@+id/imgBtn4" android:scaleType="fitCenter" android:layout_height="100dip" android:layout_width="340dip" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="@drawable/custombutton4"></ImageButton> <ImageButton android:layout_below="@id/imgBtn4" android:id="@+id/imgBtn5" android:scaleType="fitCenter" android:layout_height="100dip" android:layout_width="340dip" android:layout_marginLeft="20dip" android:layout_marginTop="5dip" android:background="@drawable/custombutton5"></ImageButton> </RelativeLayout>
and selector: (custombutton1.xml)
<?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/img_clicked" /> <item android:drawable="@drawable/img_unclicked" /> </selector>
I removed all other code from the activity to check if I was creating a memory leak. But here I jsut set the content view as my layout file, and yet my ddms say that the VM will not allow us to allocate 270,000 bytes
I donβt think I tried to manage the activity life cycles here.