Skip to content

Commit

Permalink
Cherry-pick upstream#706 (Fixing memory leaks) (#72)
Browse files Browse the repository at this point in the history
* Cherry-pick upstream#706 (Fixing memory leaks) flutter-mapbox-gl/maps#706

Co-Authored-By: Anton Averin <[email protected]>
  • Loading branch information
m0nac0 and AAverin authored May 14, 2022
1 parent 4494e8c commit 351c7bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class MaplibreMapController extends ChangeNotifier {
}

final OnStyleLoadedCallback? onStyleLoadedCallback;

final OnMapClickCallback? onMapClick;
final OnMapLongClickCallback? onMapLongClick;

Expand Down Expand Up @@ -967,4 +966,10 @@ class MaplibreMapController extends ChangeNotifier {
Future<double> getMetersPerPixelAtLatitude(double latitude) async {
return _mapboxGlPlatform.getMetersPerPixelAtLatitude(latitude);
}

@override
void dispose() {
super.dispose();
_mapboxGlPlatform.dispose();
}
}
9 changes: 9 additions & 0 deletions lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,15 @@ class _MaplibreMapState extends State<MaplibreMap> {
_mapboxMapOptions = _MapboxMapOptions.fromWidget(widget);
}

@override
void dispose() async {
super.dispose();
if (_controller.isCompleted) {
final controller = await _controller.future;
controller.dispose();
}
}

@override
void didUpdateWidget(MaplibreMap oldWidget) {
super.didUpdateWidget(oldWidget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,6 @@ abstract class MapLibreGlPlatform {
{String? belowLayerId}) async {
throw UnimplementedError('addFillLayer() has not been implemented.');
}

void dispose() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -794,4 +794,10 @@ class MethodChannelMaplibreGl extends MapLibreGlPlatform {
.map((key, value) => MapEntry<String, String>(key, jsonEncode(value)))
});
}

@override
void dispose() {
super.dispose();
_channel.setMethodCallHandler(null);
}
}

0 comments on commit 351c7bf

Please sign in to comment.