Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exponential memory usage until crash with PolylineAnnotationManager.createMulti #492

Open
ristiisa opened this issue Apr 15, 2024 · 0 comments

Comments

@ristiisa
Copy link

ristiisa commented Apr 15, 2024

Using PolylineAnnotationManager.createMulti the memory usage increases with each iteration.

image

With a slower iteration speed the increase is less dramatic.

image
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<PolylineAnnotationOptions> polylines = [];

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  MapboxOptions.setAccessToken("<TOKEN HERE>");

  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<MapSample> createState() => _MapSampleState();
}

class _MapSampleState extends State<MapSample> {
  final locationSettings = LocationComponentSettings(
    enabled: true,
    showAccuracyRing: true,
    pulsingEnabled: false,
    puckBearingEnabled: true,
    puckBearing: PuckBearing.HEADING
  );

  Stream<Position>? 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant