I'm currently porting a native iOS to Flutter. I noticed that my widget containing the map is consuming a lot of memory over 500 MB. Compared to my native iOS app, it's using x5 more memory.
I don't know what's going on cause for now I just displayed the map. With time the app is using all the available memory and as result the application is becoming unresponsive / laggy.
Also when dispose is called on the widget, the memory used is not released, do I need to do something more in the method ?
google_maps_flutter: ^2.2.1
geolocator: ^9.0.2
Below is all I use for the map so nothing special, when I remove the map's widget, the app is running fine. Any help is welcome, I have no idea where to look. Thanks
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:provider/provider.dart';
const double CAMERA_ZOOM = 16;
const double CAMERA_TILT = 80;
const double CAMERA_BEARING = 30;
class CarteWidget extends StatefulWidget {
final _CarteWidgetState carteState = _CarteWidgetState();
Key identifier;
CarteWidget(this.identifier);
@override
_CarteWidgetState createState() => carteState;
}
class _CarteWidgetState extends State<CarteWidget> {
Completer<GoogleMapController> _mapControllerCompleter = Completer();
Map<MarkerId, Marker> _markers = <MarkerId, Marker>{};
Map<PolylineId, Polyline> _polylines = <PolylineId, Polyline>{};
Map<PolygonId, Polygon> _polygons = <PolygonId, Polygon>{};
List<LatLng> polylineCoordinates = [];
MapType _mapType = MapType.hybrid;
static CameraPosition _kLogeLionne = CameraPosition(
target: LatLng(48.347628, 4.383250),
zoom: 12,
);
@override
void initState() {
super.initState();
}
void _onMapCreated(GoogleMapController controller) async {
_mapControllerCompleter.complete(controller);
setState(() {
// this._loadContent();
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: MenuWidget(),
body: Stack(
children: <Widget>[
GoogleMap(
key: widget.identifier,
initialCameraPosition: _kLogeLionne,
onMapCreated: _onMapCreated,
polylines: Set<Polyline>.of(_polylines.values),
markers: Set<Marker>.of(_markers.values),
polygons: Set<Polygon>.of(_polygons.values),
compassEnabled: true,
mapType: _mapType,
myLocationButtonEnabled: true,
myLocationEnabled: true,
rotateGesturesEnabled: true,
tiltGesturesEnabled: true,
),
],
),
);
}
void _changeMapType() {
if (this.mounted) {
setState(() {
_mapType =
_mapType == MapType.normal ? MapType.satellite : MapType.normal;
});
}
}
}
flutter doctor -v
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at /Users/idm/Library/Android/sdk • Platform android-30, build-tools 30.0.1 • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14A400 • CocoaPods version 1.11.3
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
[✓] VS Code (version 1.73.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.52.0
[✓] Connected device (3 available) • iPad (2) (mobile) • 0d90cccda2e8ecbf09cb57bbe0219aaf441b212d • ios • iOS 15.6 19G71 • macOS (desktop) • macos • darwin-x64 • macOS 12.6 21G115 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.87
[✓] HTTP Host Availability • All required HTTP hosts are available
• No issues found!