When starting my Application, the heap is at about 15M. After calling setContentView in MainActivity it raises to about 30M. There isn’t much in that layout. That’s why I’m wondering if that’s normal. When starting another Acticity, it again raises to about 40M and won’t go down again.
That’s what main.xml looks like:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:background="@drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/LinLAdMain"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_weight="0.70"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.70"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@string/logo_description"
android:src="@drawable/logo" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="0.14"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
style="@style/StartButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onClick"
android:layout_margin="8dp" />
<Button
android:id="@+id/button2"
style="@style/HighscoreButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onClick"
android:layout_margin="8dp" />
<Button
android:id="@+id/button3"
style="@style/SettingsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="onClick"
android:layout_margin="8dp" />
</LinearLayout>
</LinearLayout>
As you can see, I’m using a background-drawable. But the file is about 60K big..
And that’s what the MAT-default-report looks like right after setContentView():
This is what the paths to GC look like (excluding weak references):
These “nexts” end in head class java.lang.ref.FinalizerReference, which is telling me nothing.
As I said, it’s getting worse with every Activity. For example after
Main->Highscore->GlobalHighscore it’s no more possible to start the Activity “ingame”.
Hope you guys can help me :).
If you need more Information / Code, tell me.
Image file formats like PNG and JPG are using a compression algorithm to reduce the used disk space. However when images are loaded in android app these files are decompressed and may become much bigger then the original file.
The space used after decompression would be similar to the disk space used if you convert your PNG or JPG file to BMP 32 bits color.
An example
A very simple full white draw with size 1024 x 1024 pixels, saved as PNG will use a few Kb.
After decompression into a ARGB_8888 it becomes an array of 1024 x 1024 x 4 bytes (the last 4 stands for the 4 bytes used per pixel, one for each basic color RGB and one for Alpha)
so the memory used will be 4 MB for this simple image.
What to do
Reduce de memory used by image:
requirements for the different screen sizes you want to support
Find the memory leak that keeps memory aloocation increasing.
Probably you are using some reference to your activity
Contextthat is preventing GC to collect the memory. The most probable reasons are objects that have reference to Context/Activity:Try nulling them when no longer required, or on activity
OnDestroy()Regards.