leak_detector

This project is based on leak_detector.

1. Installation and Usage

1.1 Installation

Go to the project directory and add the following dependencies in pubspec.yaml

pubspec.yaml

...

dependencies:
  leak_detector:
    git:
      url: https://gitcode.com/openharmony-sig/flutter_leak_detector.git
      # ref: 1.1.0-ohos.1.0.0-beta.1
      ref: TAG   # Please select the TAG to the TAG Version Mapping      
...

Execute Command

flutter pub get

TAG Version Mapping

Flutter Framework Version TAG Branch
3.7 1.1.0-ohos.1.0.0-beta.1 master
3.22 1.1.0-ohos.1.0.0-beta.1 master
3.27 1.1.0-ohos.1.0.0-beta.1 master
3.35 1.1.0-ohos.1.0.0-beta.1 master

1.2 Usage

For use cases ohos/example.

2. Constraints

2.1 Compatibility

This document is verified based on the following versions:

  1. Flutter: 3.7.12-ohos-1.1.3; SDK: 5.0.0(12); IDE: DevEco Studio: 5.1.0.828; ROM: 5.1.0.130 SP8;
  2. Flutter: 3.22.1-ohos-1.0.3; SDK: 5.0.0(12); IDE: DevEco Studio: 5.1.0.828; ROM: 5.1.0.130 SP8;
  3. Flutter: 3.27.5-ohos-1.0.1; SDK: 5.0.0(12); IDE: DevEco Studio: 6.0.1.251; ROM: 6.0.0.115 SP16;
  4. Flutter: 3.35.8-ohos-0.0.1; SDK: 6.0.1(21); IDE: DevEco Studio: 6.0.1.260; ROM: 6.0.0.120 SP6;

3. API

If the value of **ohos Support** is **yes**, it means that the ohos platform supports this property; **no** means the opposite; **partially** means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.

LeakNavigatorObserver

Name Description Type Input Output ohos Support
checkLeakDelay Default delay time for leak detection int / / yes
shouldCheck Callback to determine if route is added to detection ShouldAddedRoute Route route bool yes
didPop Triggered when route is popped function Route route, Route? previousRoute void yes
didPush Triggered when route is pushed function Route route, Route? previousRoute void yes
didRemove Triggered when route is removed function Route route, Route? previousRoute void yes
didReplace Triggered when route is replaced function {Route? newRoute, Route? oldRoute} void yes

LeakDetector

Name Description Type Input Output ohos Support
maxRetainingPath Limit for VmService.getRetainingPath static int? / / yes
onLeakedStream Memory leak event stream Stream / / yes
onEventStream Detection process event stream Stream / / yes
init Initialize configuration function {int maxRetainingPath = 300} void yes
ensureReleaseAsync Asynchronous release detection function String? group, {int delay = 0} Future yes
addWatchObject Add monitored object function Object obj, String group void yes

StateLeakMixin

Name Description Type Input Output ohos Support
checkLeakDelayMill Get delay time in milliseconds getter / int yes
watchGroup Get monitoring group identifier getter / String yes
initState Initialization lifecycle method function / void yes
dispose Destruction lifecycle method function / void yes

LeakPreviewPage

Name Description Type Input Output ohos Support
leakInfoList Stores leak information list final List / / yes
showLeakedInfoPage Display single leak details function BuildContext context, LeakedInfo leakInfo void yes
showLeakedInfoListPage Display leak information list function BuildContext context, List leakInfoList void yes

LeakedRecordStore

Name Description Type Input Output ohos Support
getAll Get all leak records function / Future<List> yes
clear Clear storage function / void yes
deleteById Delete record by ID function int id void yes
addAll Batch add records function List list void yes
add Add single record function LeakedInfo info void yes

LeakedInfo

Name Description Type Input Output ohos Support
retainingPath Reference chain path List / / yes
gcRootType GC root type String? / / yes
timestamp Detection timestamp int? / / yes
isNotEmpty Check if reference chain is non-empty getter / bool yes
retainingPathJson Convert reference chain to JSON string getter / String yes

4. Properties

If the value of **ohos Support** is **yes**, it means that the ohos platform supports this property; **no** means the opposite; **partially** means some capabilities of this property are supported. The usage method is the same on different platforms and the effect is the same as that of iOS or Android.

DetectorEventType

Name Description Type Input Output ohos Support
addObject Add object event enum / / yes
check Detection event enum / / yes
startGC Start GC event enum / / yes
endGc End GC event enum / / yes
startAnalyze Start analysis event enum / / yes
endAnalyze End analysis event enum / / yes

DetectorEvent

Name Description Type Input Output ohos Support
type Event type DetectorEventType / / yes
data Event payload data dynamic / / yes

RetainingNode

Name Description Type Input Output ohos Support
clazz Class name String / / yes
parentField Parent node field name String? / / yes
libraries Library name String? / / yes
string Object string representation String? / / yes
parentKey Map parent node key String? / / yes
parentIndex List parent node index int? / / yes
sourceCodeLocation Source code location information SourceCodeLocation? / / yes
closureInfo Closure information ClosureInfo? / / yes
leakedNodeType Leak node type LeakedNodeType / / yes
important Whether node is important bool / / yes

SourceCodeLocation

Name Description Type Input Output ohos Support
code Source code snippet String? / / yes
lineNum Line number int? / / yes
columnNum Column number int? / / yes
className Class name String? / / yes
uri File path URI String? / / yes

ClosureInfo

Name Description Type Input Output ohos Support
closureFunctionName Closure function name String? / / yes
closureOwner Closure owner (class/method) String? / / yes
closureOwnerClass Closure owning class String? / / yes
libraries Library name String? / / yes
funLine Function start line number int? / / yes
funColumn Function start column number int? / / yes

5. Known Issues

6. Others

7. License

This project is licensed under The BSD-2-Clause License.