Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron009 committed Aug 11, 2021
1 parent b0776a8 commit 0ee17ff
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 402,168 deletions.
2,140 changes: 0 additions & 2,140 deletions 1.txt

This file was deleted.

12 changes: 5 additions & 7 deletions example/lib/basic_page.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:example/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_memory_leak_check/flutter_memory_leak_check.dart';

class BasicPage extends StatefulWidget {
const BasicPage({Key? key}) : super(key: key);
Expand All @@ -12,6 +12,10 @@ class _BasicPageState extends State<BasicPage> {
int _counter = 0;
List<String>? _memoryLeakList = [];

_BasicPageState() {
print("xxxxxx");
}

Future _incrementCounter() async {
_counter++;

Expand All @@ -22,7 +26,6 @@ class _BasicPageState extends State<BasicPage> {
break;
case 2:
print("start gc");
_counter = 0;
globalChecker.forceGC();
print("gc completed!");
break;
Expand All @@ -46,11 +49,6 @@ class _BasicPageState extends State<BasicPage> {
});
}

Expando x() {
var v = Expando();
return v;
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
16 changes: 13 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'package:example/basic_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_memory_leak_check/flutter_memory_leak_check.dart';

late MemoryChecker globalChecker;

void main() {
runApp(MyApp());
}
Expand All @@ -12,7 +10,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Memory Leck Check Demo',
title: 'Flutter Memory Leak Check Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
Expand All @@ -32,6 +30,10 @@ class MyHomePage extends StatefulWidget {

class _MyHomePageState extends State<MyHomePage> {

_MyHomePageState() {
print("_MyHomePageState instance");
}

@override
void initState() {
globalChecker = MemoryChecker("192.168.80.144");
Expand All @@ -40,6 +42,8 @@ class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
globalChecker.addWatch(this,);

return Scaffold(
appBar: AppBar(
title: Text(widget.title),
Expand All @@ -62,4 +66,10 @@ class _MyHomePageState extends State<MyHomePage> {
),
);
}

@override
void dispose() {
print("_MyHomePageState dispose");
super.dispose();
}
}
52 changes: 41 additions & 11 deletions lib/memory_checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:vm_service/utils.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';

import 'memory_checker_temp_prohibited_open.dart';
import 'temp.dart';

/// step 1:Add debugging options
/// --observatory-port=50443
Expand Down Expand Up @@ -48,22 +48,23 @@ class MemoryChecker {

String url = convertToWebSocketUrl(serviceProtocolUrl: uri).toString();
vmServiceConnectUri(url).then((VmService vmService) async {
//拿到vmService对象
_vmService = vmService;
vm = await _vmService.getVM();

_initMainIsolateID();
await _initLibraryID();
print("get vm service successfully");

// _vmService.streamListen("GC").then((event) {
// print("GC监听注册完毕");
// });
_vmService.streamListen("GC").then((event) {
print("GC monitoring is registered");
});
//
// _vmService.onGCEvent
// .listen(onData, onDone: onDone, onError: onError, cancelOnError: false);
});
});

initSystemList();
}

void _initMainIsolateID() {
Expand Down Expand Up @@ -105,19 +106,39 @@ class MemoryChecker {
return dataInstance!;
}

void addWatch(dynamic value, {String? remarks}) async {
if (inProduction) return;

_CodeInfo? getCodeInfo() {
try {
var v;
print(v.as);
}catch(e, s) {
String c = "$s";
print(c);
List temp = c.split('\n');
var v = temp[3];

RegExp reg = RegExp("\\((([^\\.]+)\\.dart):(\\d+):(\\d+)\\)");
Iterable<Match> matches = reg.allMatches(v);
for (Match m in matches) {
String? filePath = m.group(1);
String? line = m.group(3);
return _CodeInfo(filePath!, int.parse(line!));
}
}
}

var codeLine = CodeLine('lib/main.dart', 69, remarks: remarks);
var c = MemoryCheckerInstanceData.getInstance(_checkerClassIndex++);
void addWatch(dynamic value, {String? remarks}) async {
if (inProduction) return;
if(value == null) return;

var codeInfo = getCodeInfo();
if(codeInfo == null)
throw "Failed to get code information";

var codeLine = CodeLine(
codeInfo.filePath,
codeInfo.line,
remarks: remarks);

var c = systemList[_checkerClassIndex++];
var className = _getClassName(c);
_checkerCodeLineMap[className] = codeLine;

Expand Down Expand Up @@ -179,6 +200,8 @@ class MemoryChecker {
}
}

late MemoryChecker globalChecker;

class CodeLine {
String filePath;
int line;
Expand All @@ -194,4 +217,11 @@ class CodeLine {

Expando getMemoryCheckerExpando() {
return MemoryChecker("").expando;
}

class _CodeInfo {
late String filePath;
late int line;

_CodeInfo(this.filePath, this.line);
}

0 comments on commit 0ee17ff

Please sign in to comment.