diff --git a/integration_tests/lib/memory_leak.dart b/integration_tests/lib/memory_leak.dart index bc0a2eeb12..0e41995391 100644 --- a/integration_tests/lib/memory_leak.dart +++ b/integration_tests/lib/memory_leak.dart @@ -207,15 +207,18 @@ class HomePageElement extends StatelessElement { current = codes[currentIndex + 1]; currentIndex = currentIndex + 1; } - }, codes.length); - await sleep(Duration(seconds: 1)); - bool isLeaked = isMemLeaks(mems); + await sleep(Duration(seconds: 1)); + bool isLeaked = isMemLeaks(mems); + + print('memory leaks: ${isMemLeaks(mems)} $mems'); + if (isLeaked) { + exit(1); + } + + mems.clear(); + }, codes.length); - print('memory leaks: ${isMemLeaks(mems)}'); - if (isLeaked) { - exit(1); - } exit(0); } } @@ -254,7 +257,9 @@ class MemoryLeakNavigatorObserver extends NavigatorObserver { @override void didPush(Route route, Route? previousRoute) { super.didPush(route, previousRoute); - mems.add(ProcessInfo.currentRss / 1024); + Timer(Duration(milliseconds: 500), () { + mems.add(ProcessInfo.currentRss / 1024); + }); } @override diff --git a/integration_tests/lib/utils/mem_leak_detector.dart b/integration_tests/lib/utils/mem_leak_detector.dart index 35310f671e..de7a792adc 100644 --- a/integration_tests/lib/utils/mem_leak_detector.dart +++ b/integration_tests/lib/utils/mem_leak_detector.dart @@ -32,7 +32,7 @@ bool memoryIncreaseRatio(List memoryUsage) { bool detectMemoryLeakBasedOnRegression(List memoryUsage) { List timePoints = List.generate(memoryUsage.length, (index) => index.toDouble()); // [0.0, 1.0, 2.0, ...] double slope = linearRegressionSlope(timePoints, memoryUsage); - return slope > 5; // 如果斜率大于0,则判断为可能存在内存泄漏 + return slope > 10; } bool isMemLeaks(List mems) {