leak_detector 0.1.0-bate copy "leak_detector: ^0.1.0-bate" to clipboard
leak_detector: ^0.1.0-bate copied to clipboard

outdated

flutter memory leak detector.

leak_detector #

flutter Memory leak detection tool

Usage #

初始化

In order to prevent the underlying library vm service from crashing, please call before adding the memory leak detection object:

LeakDetector().init(maxRetainingPath: 300); //maxRetainingPath default is 300

Enabling leak detection will reduce performance, and Full GC may drop frames on the page. Initialized by assert in the plugin, so you don't need to turn it off when build on release mode.

Detect

On your State class mixin StateLeakMixin, this will automatically detect whether there is a memory leak in the State and its corresponding Element objects.

import 'package:leak_detector/leak_detector.dart';

class LeakedPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return TestPageState();
  }
}

class LeakedPageState extends State<TestPage> with StateLeakMixin {
  @override
  Widget build(BuildContext context) {
    return ...;
  }
}

Get leaked information

LeakDetector().onLeakedStream can register your listener, and notify the object's reference chain after detecting a memory leak. LeakDetector().onEventStream can monitor internal time notifications, such as start Gc, end Gc, etc.

A preview page of the reference chain is provided. You only need to add the following code. Note that the Bulid Context must be able to obtain theNavigatorState:

import 'package:leak_detector/leak_detector.dart';

//show preview page
LeakDetector().onLeakedStream.listen((LeakedInfo info) {
  //print to console
  info.retainingPath.forEach((node) => print(node));
  //show preview page
  showLeakedInfoPage(navigatorKey.currentContext, info);
});

Preview page display:

It contains the class information of the reference chain node, the referenced attribute information, the source code of the attribute declaration, and the location of the source code (line number: column number).

Get memory leak recording

import 'package:leak_detector/leak_detector.dart';

getLeakedRecording().then((List<LeakedInfo> infoList) {
  showLeakedInfoListPage(navigatorKey.currentContext, infoList);
});
47
likes
0
pub points
86%
popularity

Publisher

unverified uploader

flutter memory leak detector.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, path, sqflite, vm_service

More

Packages that depend on leak_detector