mapbox / mapbox/mapbox-maps-flutter
Exponential memory usage until crash with PolylineAnnotationManager.createMulti
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Dart
- Sterne
- 380
- Forks
- 204
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- dart, flutter
- Bereich
- mobile
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100