Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kyv fix leak navigation map route option keep lifecycle observer #3012

Conversation

RingerJK
Copy link
Contributor

@RingerJK RingerJK commented May 21, 2020

Description

Another option how to solve memory leak
First is #3007

  • I have added any issue links
  • I have added all related labels (bug, feature, new API(s), SEMVER, etc.)
  • I have added the appropriate milestone and project boards

Goal

Please describe the PR goals. Just the stuff needed to implement the fix / feature and a simple rationale. It could contain many check points if needed

Implementation

Please include all the relevant things implemented and also rationale, clarifications / disclaimers etc. related to the approach used. It could be as self code companion comments

Screenshots or Gifs

Please include all the media files to give some context about what's being implemented or fixed. It's not mandatory to upload screenshots or gifs, but for most of the cases it becomes really handy to get into the scope of the feature / bug being fixed and also it's REALLY useful for UI related PRs screenshot gif

Testing

Please describe the manual tests that you ran to verify your changes

  • I have tested locally (including SNAPSHOT upstream dependencies if needed) through testapp/demo app and run all activities to avoid regressions
  • I have tested via a test drive, or a simulation/mock location app
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have updated the CHANGELOG including this PR

@RingerJK RingerJK added bug Defect to be fixed. quick fix labels May 21, 2020
@RingerJK RingerJK added this to the v1.0.0 milestone May 21, 2020
@RingerJK RingerJK self-assigned this May 21, 2020
@RingerJK
Copy link
Contributor Author

Here's no documentation for new methods just because it's another option how to fix leak. If we'd approve this approach I'll add docs 🙈

@NonNull MapboxMap mapboxMap) {
this(mapView, mapboxMap, null);
@NonNull MapboxMap mapboxMap,
@NonNull LifecycleOwner lifecycleOwner) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that this would break SemVer cc @langsmith

@@ -115,8 +125,9 @@ public NavigationMapboxMap(@NonNull MapView mapView,
*/
public NavigationMapboxMap(@NonNull MapView mapView,
@NonNull MapboxMap mapboxMap,
@NonNull LifecycleOwner lifecycleOwner,
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that this would break SemVer cc @langsmith

@@ -129,8 +140,9 @@ public NavigationMapboxMap(@NonNull MapView mapView,
*/
public NavigationMapboxMap(@NonNull MapView mapView,
@NonNull MapboxMap mapboxMap,
@NonNull LifecycleOwner lifecycleOwner,
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that this would break SemVer cc @langsmith

@@ -144,11 +156,13 @@ public NavigationMapboxMap(@NonNull MapView mapView,
*/
public NavigationMapboxMap(@NonNull MapView mapView,
@NonNull MapboxMap mapboxMap,
@NonNull LifecycleOwner lifecycleOwner,
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that this would break SemVer cc @langsmith

Comment on lines -60 to -160
* Construct an instance of {@link NavigationMapRoute}.
*
* @param mapView the MapView to apply the route to
* @param mapboxMap the MapboxMap to apply route with
* @since 0.4.0
*/
public NavigationMapRoute(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap) {
this(null, mapView, mapboxMap, R.style.NavigationMapRoute);
}

/**
* Construct an instance of {@link NavigationMapRoute}.
*
* @param mapView the MapView to apply the route to
* @param mapboxMap the MapboxMap to apply route with
* @param belowLayer optionally pass in a layer id to place the route line below
* @since 0.4.0
*/
public NavigationMapRoute(@NonNull MapView mapView, @NonNull MapboxMap mapboxMap,
@Nullable String belowLayer) {
this(null, mapView, mapboxMap, R.style.NavigationMapRoute, belowLayer);
}

/**
* Construct an instance of {@link NavigationMapRoute}.
*
* @param navigation an instance of the {@link MapboxNavigation} object. Passing in null means
* your route won't consider rerouting during a navigation session.
* @param mapView the MapView to apply the route to
* @param mapboxMap the MapboxMap to apply route with
* @since 0.4.0
*/
public NavigationMapRoute(@Nullable MapboxNavigation navigation, @NonNull MapView mapView,
@NonNull MapboxMap mapboxMap) {
this(navigation, mapView, mapboxMap, R.style.NavigationMapRoute);
}

/**
* Construct an instance of {@link NavigationMapRoute}.
*
* @param navigation an instance of the {@link MapboxNavigation} object. Passing in null means
* your route won't consider rerouting during a navigation session.
* @param mapView the MapView to apply the route to
* @param mapboxMap the MapboxMap to apply route with
* @param belowLayer optionally pass in a layer id to place the route line below
* @since 0.4.0
*/
public NavigationMapRoute(@Nullable MapboxNavigation navigation, @NonNull MapView mapView,
@NonNull MapboxMap mapboxMap, @Nullable String belowLayer) {
this(navigation, mapView, mapboxMap, R.style.NavigationMapRoute, belowLayer);
}

/**
* Construct an instance of {@link NavigationMapRoute}.
*
* @param navigation an instance of the {@link MapboxNavigation} object. Passing in null means
* your route won't consider rerouting during a navigation session.
* @param mapView the MapView to apply the route to
* @param mapboxMap the MapboxMap to apply route with
* @param styleRes a style resource with custom route colors, scale, etc.
*/
public NavigationMapRoute(@Nullable MapboxNavigation navigation, @NonNull MapView mapView,
@NonNull MapboxMap mapboxMap, @StyleRes int styleRes) {
this(navigation, mapView, mapboxMap, styleRes, null);
}

/**
* Construct an instance of {@link NavigationMapRoute}.
*
* @param navigation an instance of the {@link MapboxNavigation} object. Passing in null means
* your route won't consider rerouting during a navigation session.
* @param mapView the MapView to apply the route to
* @param mapboxMap the MapboxMap to apply route with
* @param styleRes a style resource with custom route colors, scale, etc.
* @param belowLayer optionally pass in a layer id to place the route line below
*/
public NavigationMapRoute(@Nullable MapboxNavigation navigation, @NonNull MapView mapView,
@NonNull MapboxMap mapboxMap, @StyleRes int styleRes,
@Nullable String belowLayer) {
this(navigation, mapView, mapboxMap, styleRes, belowLayer, false, null);
}

/**
* Construct an instance of {@link NavigationMapRoute}.
*
* @param navigation an instance of the {@link MapboxNavigation} object. Passing in null means
* your route won't consider rerouting during a navigation session.
* @param mapView the MapView to apply the route to
* @param mapboxMap the MapboxMap to apply route with
* @param styleRes a style resource with custom route colors, scale, etc.
* @param belowLayer optionally pass in a layer id to place the route line below
* @param routeLineInitializedCallback called to indicate that the route line layer has been added
* to the current style
*/
public NavigationMapRoute(@Nullable MapboxNavigation navigation, @NonNull MapView mapView,
@NonNull MapboxMap mapboxMap, @StyleRes int styleRes,
@Nullable String belowLayer,
@Nullable MapRouteLineInitializedCallback routeLineInitializedCallback) {
this(navigation, mapView, mapboxMap, styleRes, belowLayer, false, routeLineInitializedCallback);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that this would break SemVer cc @langsmith

Comment on lines 77 to 86
private NavigationMapRoute(@Nullable MapboxNavigation navigation,
@NonNull MapView mapView,
@NonNull MapboxMap mapboxMap,
@NonNull LifecycleOwner lifecycleOwner,
@StyleRes int styleRes,
@Nullable String belowLayer,
Boolean vanishRouteLineEnabled,
@Nullable MapRouteLineInitializedCallback routeLineInitializedCallback) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Noting that this would break SemVer cc @langsmith

@Guardiola31337 Guardiola31337 added backwards incompatible Requires a SEMVER major version change. UI Work related to visual components, Android Auto, Camera, 3D, voice, etc. labels May 21, 2020
@RingerJK RingerJK marked this pull request as draft May 21, 2020 18:29
@RingerJK
Copy link
Contributor Author

Converted to draft, because it's one of option, but still ready for review

Copy link
Contributor

@cafesilencio cafesilencio left a comment

Choose a reason for hiding this comment

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

Ultimately I think this is a better implementation than what's currently in place.

@RingerJK RingerJK mentioned this pull request May 22, 2020
10 tasks
@codecov-commenter
Copy link

codecov-commenter commented May 22, 2020

Codecov Report

Merging #3012 into master will decrease coverage by 0.01%.
The diff coverage is 18.60%.

@@             Coverage Diff              @@
##             master    #3012      +/-   ##
============================================
- Coverage     36.78%   36.76%   -0.02%     
  Complexity     2215     2215              
============================================
  Files           553      553              
  Lines         19975    19982       +7     
  Branches       1885     1882       -3     
============================================
- Hits           7348     7347       -1     
- Misses        11789    11796       +7     
- Partials        838      839       +1     

@RingerJK RingerJK marked this pull request as ready for review May 22, 2020 15:06
@RingerJK
Copy link
Contributor Author

Ultimately I think this is a better implementation than what's currently in place.

@cafesilencio thanks, could you take a 👀 again.

PS commits will be squashed before merge

@@ -223,9 +220,6 @@ public void onPause() {

public void onStop() {
mapView.onStop();
if (navigationMap != null) {
navigationMap.onStop();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does onStop need lifecycleRegistry.markState(Lifecycle.State.STOPPED); as I see in onStart?

Copy link
Contributor

Choose a reason for hiding this comment

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

This may be outside of the scope of your PR so I don't think merging depends on this necessarily but it caught my attention so if we could at least create a ticket to investigate whether lifecycleRegistry.markState(Lifecycle.State.STOPPED) is needed that would be great so we don't lose track of it.

Besides that, I reviewed the changes again. I think this is the right way to go and I think the changes should be merged in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cafesilencio definitely it's not a right way how NavigationView should work 👍
I've created separate issue #3024 for missing calls. Would be great investigate and fix it in separate PR because here might be more than one missing call(have a look on fun onPause(), missing call as well)
If everything is ok I need ✅

@cafesilencio cafesilencio self-requested a review May 22, 2020 21:04
@cafesilencio
Copy link
Contributor

cafesilencio commented May 22, 2020 via email

@RingerJK RingerJK force-pushed the kyv-fix-leak-navigation-map-route-option-keep-lifecycle-observer branch from f2edd3f to 33aa427 Compare May 22, 2020 21:06
@RingerJK
Copy link
Contributor Author

@cafesilencio thanks!

@RingerJK RingerJK force-pushed the kyv-fix-leak-navigation-map-route-option-keep-lifecycle-observer branch 2 times, most recently from 81da820 to 645066d Compare May 25, 2020 09:00
@RingerJK
Copy link
Contributor Author

Crashes because of #3024

@RingerJK RingerJK force-pushed the kyv-fix-leak-navigation-map-route-option-keep-lifecycle-observer branch from 645066d to 5a0acf0 Compare May 27, 2020 09:50
…tionMapboxMap and NavigationMapRoute pass LifecycleOwner explicitly.
@RingerJK RingerJK force-pushed the kyv-fix-leak-navigation-map-route-option-keep-lifecycle-observer branch from 5a0acf0 to e537d5b Compare May 27, 2020 11:33
@RingerJK RingerJK merged commit f05c901 into master May 27, 2020
@RingerJK RingerJK deleted the kyv-fix-leak-navigation-map-route-option-keep-lifecycle-observer branch May 27, 2020 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards incompatible Requires a SEMVER major version change. bug Defect to be fixed. UI Work related to visual components, Android Auto, Camera, 3D, voice, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants