Repository navigation
Closed
Description
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.
Metadata
Metadata
Assignees
Labels
No labels
Activity
tonnyavery commentedon 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.
tonnyavery commentedon 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.
tonnyavery commentedon Aug 23, 2020
Also the case on latest flutter 1.20.2 version
TimothySealy commentedon Aug 24, 2020
Hi @aaverin, have you looked at issue #226? On iOS it seems that the (native)
MapBoxControlleris not cleaned up. PR #370 should fix this. Not sure if there is a similar issue for Android.tonnyavery commentedon 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
tonnyavery commentedon 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.
tonnyavery commentedon 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.
tonnyavery commentedon 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
tonnyavery commentedon 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 commentedon Jun 16, 2023
Some solution here?
tonnyavery commentedon 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