liodali / osm_flutter

OpenStreetMap plugin for flutter
https://pub.dev/packages/flutter_osm_plugin
MIT License
239 stars 98 forks source link

Memory leak when using OSMFlutter widget in route causes app crash #564

Open ricowp81 opened 1 month ago

ricowp81 commented 1 month ago

Description:

There seems to be a memory leak when using the OSMFlutter widget inside a route. When navigating in and out of this route multiple times, the memory is not released properly, causing the app to crash after a while due to excessive memory usage.

code

class SetLocationView extends StatefulWidget {
  const SetLocationView({super.key});

  @override
  State<SetLocationView> createState() => _SetLocationViewState();
}

class _SetLocationViewState extends State<SetLocationView> {
  late final MapController controller;

  @override
  void initState() {
    controller = MapController(
      initPosition: GeoPoint(
        longitude: -99.503415,
        latitude: 17.547804,
      ),
    );
    super.initState();
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Consumer<SetLocationViewModel>(
        builder: (context, vm, _) {
          return Stack(
            children: [
              OSMFlutter(
                controller: controller,
                osmOption: const OSMOption(
                  isPicker: true,
                ),
              ),
              AppBarADSGVariant(
                title: AppLocalizations.of(context)!.set_location,
                actions: const [
                  CircleAvatar(
                    radius: 25.0,
                    backgroundColor: ColorsADSG.primary,
                    foregroundColor: ColorsADSG.onPrimary,
                    child: Icon(Symbols.add_location_alt_rounded),
                  )
                ],
                children: [
                  Text(AppLocalizations.of(context)!.last_known_location),
                  const SizedBox(height: 16.0),
                  FilledTextField(
                    margin: EdgeInsets.zero,
                    labelText: AppLocalizations.of(context)!.search,
                    prefix: Container(
                      margin: const EdgeInsets.only(left: 16.0),
                      child: const Icon(Symbols.search)
                    )
                  ),
                ],
              )
            ],
          );
        }
      ),
    );
  }
}

images

image image
liodali commented 1 month ago

do you have any log for crash ?

ricowp81 commented 1 month ago
The app “Runner” has been killed by the operating system because it is using too much memory.
Domain: IDEDebugSessionErrorDomain
Code: 11
Recovery Suggestion: Use a memory profiling tool to track the process memory usage.
User Info: {
    DVTErrorCreationDateKey = "2024-09-24 14:08:45 +0000";
    IDERunOperationFailingWorker = DBGLLDBLauncher;
}
--

For more detailed information on the app's behavior when it crashes, please refer to: https://drive.google.com/file/d/1KLy1qDTLWVjvv0nQBKw4IiCjB_r357P9/view?usp=share_link