mapbox / mapbox/mapbox-maps-flutter
Exponential memory usage until crash with PolylineAnnotationManager.createMulti
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 380
- Forks
- 204
- PR merge metrics
- No merged PRs in 30d
Description
Using PolylineAnnotationManager.createMulti the memory usage increases with each iteration.
With a slower iteration speed the increase is less dramatic.
```dart
import 'dart:async';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mapbox_maps_flutter/mapbox_maps_flutter.dart';
List polylines = [];
void main() async {
WidgetsFlutterBinding.ensureInitialized();
MapboxOptions.setAccessToken("");
var data = json.decode(await rootBundle.loadString("path.json")) as List;
for(var n = 0; n < 10; n++) polylines.addAll(data.map((e) => PolylineAnnotationOptions(
geometry: e,
lineWidth: 5.0,
lineColor: Colors.red.value,
lineJoin: LineJoin.ROUND,
)).toList());
runApp(MaterialApp(home: MapSample()));
}
class MapSample extends StatefulWidget {
@override
State createState() => _MapSampleState();
}
class _MapSampleState extends State {
final locationSettings = LocationComponentSettings(
enabled: true,
showAccuracyRing: true,
pulsingEnabled: false,
puckBearingEnabled: true,
puckBearing: PuckBearing.HEADING
);
Stream? location;
PolylineAnnotationManager? polylineAnnotationManager;
@override
initState() {
super.initState();
}
@override
Widget build(BuildContext context) => Scaffold(
body: MapWidget(
key: ValueKey("map"),
cameraOptions: CameraOptions(center: Point(coordinates: Position(-122.04160728, 37.33676622)), zoom: 12, pitch: 0.0),
onMapCreated: (mapboxMap) async {
await Future.wait([
mapboxMap.scaleBar.updateSettings(ScaleBarSettings(enabled: false)),
mapboxMap.gestures.updateSettings(GesturesSettings(rotateEnabled: false)),
mapboxMap.attribution.updateSettings(AttributionSettings(clickable: false, iconColor: 1)),
mapboxMap.location.updateSettings(locationSettings),
]);
polylineAnnotationManager ??= await mapboxMap.annotations.createPolylineAnnotationManager();
Timer.periodic(const Duration(milliseconds: 100), (_) async {
polylineAnnotationManager!.deleteAll();
await polylineAnnotationManager!.createMulti(polylines!);
});
}
)
);
}
```
https://github.com/ristiisa/mbmemleak/tree/annotations
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PolylineAnnotationManager.createMulti and deleteAll calls in the provided Dart reproduction, especially the Timer.periodic loop. Run the mbmemleak/annotations reproduction and monitor memory while repeating the loop; done means repeated deletion and creation no longer causes unbounded memory growth or a crash.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100