I have created very simple activity TempActivity with no contentview, just for testing purpose. When this activity loads into android phone, I did around 40 times orientation change, I took heap file as hprof and exported to MAT tool and inspected. It shows 40 instance of my TempActivity, and in each instance many classes for actionbar view like linearlayout, imageview etc.
Each time whenever I rotate screen, DDMS shows more and more memory added to heap for this application, ideally shouldn't it be garbage collected after some time? When I forcefully did GC, still it didnt get cleared and it shows increased memory in heap.
Please let me know that is this the default behavior of Android, can we do something to remove all previous instances of an activity? Is this the case of memory leak? Because in my realtime application (with images and other stuff in contentview), I face the same issue when i rotate screen , each time new instance activity is created and heap size keeps increasing.
Is it not because of default ActionBar imageview, linearlayout or other controls automatically inbuilt each android activity right?
Here is my temp activity class:
[Activity(Label = "TempAcivity", MainLauncher = true)]
public class TempAcivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Create your application here
}
}
EDIT
Here is my manifest file and style file which is applied for application
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="HF.Mobility.Android" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="21" />
<application android:label="Health Hub" android:theme="@style/CustomHoloTheme" android:icon="@drawable/ApplicationIcon" android:allowBackup="false">
<application android:label="@string/ApplicationName"></application>
</application>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
</manifest>
Style file:
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="CustomHoloTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:icon">@android:color/transparent</item>
<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
<item name="android:itemTextAppearance">@style/myCustomMenuTextApearance </item>
<item name="android:typeface">monospace</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
<item name="android:background">@drawable/actionbar_background</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#FFFFFF</item>
</style>
<style name="myCustomMenuTextApearance" parent="@android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">@color/xam_green</item>
</style>
</resources>
Here is actionbar_background.xml file :
<?xml version="1.0" encoding="utf-8" ?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>