Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Avoid leaking compassView context through animator #13743

Merged
merged 1 commit into from
Jan 17, 2019
Merged

Conversation

tobrun
Copy link
Member

@tobrun tobrun commented Jan 16, 2019

@tobrun tobrun added the Android Mapbox Maps SDK for Android label Jan 16, 2019
@tobrun tobrun added this to the android-v7.1.0 milestone Jan 16, 2019
@tobrun tobrun self-assigned this Jan 16, 2019
@@ -411,6 +411,11 @@ public void onDestroy() {
mapCallback.onDestroy();
initialRenderCallback.onDestroy();

if (compassView != null) {
// avoid leaking context through animator #13742
compassView.resetAnimation();
Copy link
Member

Choose a reason for hiding this comment

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

Thinking in terms of https://github.com/mapbox/mapbox-gl-native/issues/13152, maybe we can use compassView.setEnabled(false) here to limit the amount of publicly exposed methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

the enabled flag is also used for saving instance state:

    outState.putBoolean(MapboxConstants.STATE_COMPASS_ENABLED, isCompassEnabled());

Since we do not control the execution order for OnDestroy vs OnSaveInstance state. We could end up in a situation where the compass remains disabled when recreating the underlying context while it initially was enabled.

Copy link
Member

Choose a reason for hiding this comment

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

I believe that onSaveInstanceState is always going to be called before onDestroy, this is the takeaway I get from the docs. That said, I don't have strong feelings about this, so :shipit:.

Copy link
Member Author

Choose a reason for hiding this comment

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

For normal cases as an Activity yes, but since our MapView#OnDestroy is called from Fragment#onDestroyView it can occur that MapView#OnSaveInstanceState is called after MapView#OnDestroy. For example destroying an Activity while you have a MapView fragment in the backstack.

Copy link
Member

Choose a reason for hiding this comment

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

Good point 👍

@tobrun tobrun merged commit 6e856eb into master Jan 17, 2019
@tobrun tobrun deleted the tvn-leak-compassview branch January 17, 2019 11:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants