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

MapboxMap leaking #389

Closed
AAverin opened this issue Aug 21, 2020 · 11 comments · Fixed by #706
Closed

MapboxMap leaking #389

AAverin opened this issue Aug 21, 2020 · 11 comments · Fixed by #706

Comments

@AAverin
Copy link
Contributor

AAverin commented Aug 21, 2020

Having just this map in my widget

class StaticMapWidget extends HookWidget {
  final Spot spot;

  StaticMapWidget(this.spot);

 @override
  Widget build(BuildContext context) {
    final Completer<MapboxMapController> _controller = useMemoized(() => Completer());
    return Container(
      height: 300,
      child: MapboxMap(
          initialCameraPosition: CameraPosition(
              target: LatLng(spot.location.latitude, spot.location.longitude), zoom: 14),
          styleString: MapboxStyles.MAPBOX_STREETS
          ),
    );
  }
}

If I open my screen with map 3 times and go back, I still get 1 instance of my widget kept in memory. There is also 1 instance of MapboxMap sitting in memory.

Having my widget implemented with extra map callbacks:

class StaticMapWidget extends HookWidget {
  final Spot spot;

  StaticMapWidget(this.spot);

  @override
  Widget build(BuildContext context) {
    final Completer<MapboxMapController> _controller = useMemoized(() => Completer());

    final onMapCreated = useMemoized(
        () => (controller) {
              if (!_controller.isCompleted) _controller.complete(controller);
            },
        [spot]);

    final onStyleLoaded = useMemoized(
        () => () async {
              final MapboxMapController map = await _controller.future;
              await map.clearSymbols();
              vm.getMarkers().forEach((element) async {
                await map.addSymbol(element);
              });
            },
        [spot]);

    return Container(
      height: 300,
      child: MapboxMap(
          initialCameraPosition: CameraPosition(
              target: LatLng(spot.location.latitude, spot.location.longitude), zoom: 14),
          styleString: MapboxStyles.MAPBOX_STREETS,
          onMapCreated: onMapCreated,
          onStyleLoadedCallback: onStyleLoaded
          ),
    );
  }
}

Running the screen with widget 3 times and going back, I still see 3 instance of my widget and 3 instance of MapboxMap in memory.

@AAverin
Copy link
Contributor Author

AAverin commented Aug 21, 2020

I have been debugging this leak for the last few days and I am 100% sure none of my code is causing the leak. I also made sure that Spot that I pass inside doesn't cause the leak and even tested HookWidget itself.
The only variable left is MapboxMap.

@AAverin
Copy link
Contributor Author

AAverin commented Aug 22, 2020

Just to add some more details. Because leak is there on both iOS and Android emulators, I suspect that Flutter implementation is causing the leak, not the native view.

@AAverin
Copy link
Contributor Author

AAverin commented Aug 23, 2020

Also the case on latest flutter 1.20.2 version

@TimothySealy
Copy link
Collaborator

Hi @AAverin, have you looked at issue #226? On iOS it seems that the (native) MapBoxController is not cleaned up. PR #370 should fix this. Not sure if there is a similar issue for Android.

@AAverin
Copy link
Contributor Author

AAverin commented Aug 25, 2020

@TimothySealy I would need to test after the PR is merged, but I am quite confident that I had the leak present on both iOS and Android when testing

@AAverin
Copy link
Contributor Author

AAverin commented Sep 5, 2020

I think the leak is mostly related to iOS, I don't notice any more laggy behavior on Android. Will look into memory profile later to confirm, but we should focus on iOS because now map is almost unusable there.

@AAverin
Copy link
Contributor Author

AAverin commented Sep 9, 2020

@m0nac0 Can I help in any way to solve this and other iOS performance issues? I can't release the iOS version of the project because of that.

@AAverin
Copy link
Contributor Author

AAverin commented Nov 6, 2020

I will close this one for now, map is much more performant on iOS device and issues with iOS emulator should be resolved by #413

@AAverin AAverin closed this as completed Nov 6, 2020
@AAverin
Copy link
Contributor Author

AAverin commented Oct 4, 2021

I am reopening this one because I get a consistent leak with multiple instances of MapboxMap and MapboxMapController even if I don't attach any callbacks to the widget and do nothing.
Reproducible on Android and iOS both.

@Layoneth
Copy link

Some solution here?

@AAverin
Copy link
Contributor Author

AAverin commented Jun 16, 2023

@Layoneth i don't get any leaks anymore in the app, having multiple different places where I show the map.

If you still experience problems best would be to debug on your usage case, find the cause and propose a fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants