Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Fix several Android memory leaks #360

Merged
merged 1 commit into from Sep 27, 2016
Merged

Conversation

hartez
Copy link
Contributor

@hartez hartez commented Sep 15, 2016

Description of Change

Fixes for several memory leaks on Android. Changes include:

  • Calling Destroy() on Map during disposal (leaking the Map object)
  • Cleaning up OnFocusChangeListener on ViewRenderer during disposal (leaking various renderers)
  • Cleaning up listeners and tag on ButtonRenderer during disposal (leaking ButtonRenderer)
  • Fixing bug where animated fragment transactions leaked FragmentContainer and PageContainer

Bugs Fixed

API Changes

None

Behavioral Changes

None

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense

Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small questions and comments

if (disposing && !_disposed) {
_disposed = true;
if (_disposed)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could drop { here

if (mapModel != null) {
MessagingCenter.Unsubscribe<Map, MapSpan> (this, MoveMessageName);
((ObservableCollection<Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged;
if (disposing)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if !disposing return ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't return right here, still need to call base.Dispose(disposing).

}
// We do *not* eagerly dispose of the _pageContainer here; doing so causes a memory leak
// if animated fragment transitions are enabled (it removes some info that the animation's
// onAnimationEnd handler requires to properly clean things up)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OHHH

{
tcs.TrySetResult(true);
fragment.UserVisibleHint = true;
fragment.UserVisibleHint = !removed;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where does remove get set? after animation ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's one of the parameters to SwitchContentAsync (the method we're in right now).

NativeMap.MyLocationEnabled = false;
NativeMap.SetOnCameraChangeListener(null);
NativeMap.InfoWindowClick -= MapOnMarkerClick;
NativeMap.Dispose();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NativeMap = null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NativeMap refers to MapView.Map, which is read-only.

Control.RemoveOnAttachStateChangeListener(this);
Control.Tag = null;
_textColorSwitcher = null;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control = null;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not here. The base class ViewRenderer<TView, TNativeView> still has some cleanup to do on Control, then it gets set to null.

((ObservableCollection<Pin>)mapModel.Pins).CollectionChanged -= OnCollectionChanged;
if (disposing)
{
_disposed = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed. This is already done above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

@rmarinho
Copy link
Member

Needs rebase

Clean up OnFocusChangeListener on ViewRenderer during disposal
Prevent memory leak of PageContainer/FragmentContainer when animating fragment transitions
Call Destroy() on Map during disposal

Rebasing
@rmarinho rmarinho merged commit 6aa96a4 into master Sep 27, 2016
@rmarinho rmarinho deleted the fix-bugzilla39489-part2 branch September 27, 2016 10:55
@samhouts samhouts added this to the 2.3.4 milestone Jun 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants