I track usage and memory leak in my Android Xamarin project and decided to start with one of the simple pages.
When starting the panel / launch activity, I have 21.790 MB of allocated memory and a heap size of 26.016 MB.
When I open a help action, I simply create an action using the OnCreate method, similar to:
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.HelpActivity);
ActionBar.SetDisplayHomeAsUpEnabled(true);
_quickstartGuideLinearLayout = FindViewById<LinearLayout>(Resource.Id.quickstart_guide_layout);
_quickstartGuideLinearLayout.Click += ViewQuickstart;
_usermanualLinearLayout = FindViewById<LinearLayout>(Resource.Id.user_manual_layout);
_usermanualLinearLayout.Click += ViewUserManual;
}
and then in OnDestroy:
protected override void OnDestroy()
{
if (_quickstartGuideLinearLayout != null)
{
_quickstartGuideLinearLayout.Click -= ViewQuickstart;
_quickstartGuideLinearLayout.Dispose();
_quickstartGuideLinearLayout = null;
}
if (_usermanualLinearLayout != null)
{
_usermanualLinearLayout.Click -= ViewUserManual;
_usermanualLinearLayout.Dispose();
_usermanualLinearLayout = null;
}
base.OnDestroy();
}
Memory usage will increase to 22.102 MB when help activity is shown, and when I press the back button or the up button on the action bar, it will drop to 22.078 MB.
Why does this not return to 21.790 MB if the help activity is destroyed?