Reputation: 28
When I load up my app, It takes around 3Mb of RAM. I have an ImageButton
on my first activity which calls the function showRecords
, which displays a dialog box.
Once the dialog box is opened, it can be closed by clicking outside of the box (which will call the dismiss()
method). The problem I am having is that after the dialog box has been closed, the amount of RAM used by my application does not return to its previous state (it can remain over a Mb more If I include another stuff in the dialog - but the example retains around 2-300kb)
public void showRecords(View v){
Dialog recordDialog = new Dialog(this);
recordDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
recordDialog.setCanceledOnTouchOutside(true);
recordDialog.setContentView(R.layout.record);
recordDialog.show();
}
The record.xml file has an image background, and another ImageView with a picture.
I have tried using MAT, and can see no Dialog objects in memory. I also have been using DDMS to perform garbage collections, but the RAM value never returns to what I would expect.
Is something binding to the activity? or is the GC just refusing the reclaim the memory?
As this is my first activity, it remains alive throughout and doesn't seem to close if I need more heap space (for some reason). Therefore I'm quite interested in reclaiming a Mb of memory when it is not needed.
EDIT - record.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:orientation="vertical"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/recordspage"
android:layout_marginTop="5dp"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
/>
</LinearLayout>
Upvotes: 1
Views: 300
Reputation: 1006869
OK, now that the analysis is out of the way... :-)
Bitmap resources take a hunk of heap space, because in memory they are held in their raw uncompressed format, compared to the PNG or JPEG you probably started with.
I notice that you are setting a background on a LinearLayout
. That certainly works, but bitmap backgrounds are perhaps the biggest memory hogs, just due to their size. You might consider going with a flat color, a ShapeDrawable
, or something that is less heap-intensive, if you are concerned about the space. This is particularly true for a dialog box, which is usually on the screen for mere moments.
Upvotes: 1