|
@@ -9,6 +9,8 @@ import 'package:logging/logging.dart';
|
|
|
import 'package:puzzleweave/firebase/firebase_helper.dart';
|
|
import 'package:puzzleweave/firebase/firebase_helper.dart';
|
|
|
import 'package:puzzleweave/models/download.dart';
|
|
import 'package:puzzleweave/models/download.dart';
|
|
|
|
|
|
|
|
|
|
+import '../config/config.dart';
|
|
|
|
|
+
|
|
|
final Logger _log = Logger('MemoryMonitor');
|
|
final Logger _log = Logger('MemoryMonitor');
|
|
|
|
|
|
|
|
/// 内存阶段定义
|
|
/// 内存阶段定义
|
|
@@ -32,7 +34,7 @@ class MemoryMonitor with WidgetsBindingObserver {
|
|
|
|
|
|
|
|
VoidCallback? _onHighMemory;
|
|
VoidCallback? _onHighMemory;
|
|
|
VoidCallback? _onCriticalMemory;
|
|
VoidCallback? _onCriticalMemory;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// Release模式下的内存显示
|
|
// Release模式下的内存显示
|
|
|
static final ValueNotifier<String> memoryDisplay = ValueNotifier<String>('Memory: 0MB');
|
|
static final ValueNotifier<String> memoryDisplay = ValueNotifier<String>('Memory: 0MB');
|
|
|
|
|
|
|
@@ -110,7 +112,7 @@ class MemoryMonitor with WidgetsBindingObserver {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
final memoryMB = getCurrentMemoryMB();
|
|
final memoryMB = getCurrentMemoryMB();
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 更新UI显示
|
|
// 更新UI显示
|
|
|
memoryDisplay.value = 'Memory: ${memoryMB.toStringAsFixed(1)}MB';
|
|
memoryDisplay.value = 'Memory: ${memoryMB.toStringAsFixed(1)}MB';
|
|
|
|
|
|
|
@@ -185,15 +187,17 @@ class MemoryMonitor with WidgetsBindingObserver {
|
|
|
|
|
|
|
|
/// 供外部在关键节点(如播广告前)手动清理
|
|
/// 供外部在关键节点(如播广告前)手动清理
|
|
|
void manualCleanup() {
|
|
void manualCleanup() {
|
|
|
|
|
+ if (!Config.isDebug) return;
|
|
|
_emergencyCleanup(reason: 'manual_call');
|
|
_emergencyCleanup(reason: 'manual_call');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void logMemoryUsage(String label) {
|
|
static void logMemoryUsage(String label) {
|
|
|
|
|
+ if (!Config.isDebug) return;
|
|
|
final memoryMB = getCurrentMemoryMB();
|
|
final memoryMB = getCurrentMemoryMB();
|
|
|
memoryDisplay.value = '[$label] ${memoryMB.toStringAsFixed(1)}MB';
|
|
memoryDisplay.value = '[$label] ${memoryMB.toStringAsFixed(1)}MB';
|
|
|
_log.info('[$label] RSS Memory: ${memoryMB.toStringAsFixed(1)} MB');
|
|
_log.info('[$label] RSS Memory: ${memoryMB.toStringAsFixed(1)} MB');
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
/// 获取内存显示组件(供Release模式使用)
|
|
/// 获取内存显示组件(供Release模式使用)
|
|
|
static Widget getMemoryWidget() {
|
|
static Widget getMemoryWidget() {
|
|
|
return ValueListenableBuilder<String>(
|
|
return ValueListenableBuilder<String>(
|
|
@@ -201,14 +205,8 @@ class MemoryMonitor with WidgetsBindingObserver {
|
|
|
builder: (context, value, child) {
|
|
builder: (context, value, child) {
|
|
|
return Container(
|
|
return Container(
|
|
|
padding: EdgeInsets.all(4),
|
|
padding: EdgeInsets.all(4),
|
|
|
- decoration: BoxDecoration(
|
|
|
|
|
- color: Colors.black54,
|
|
|
|
|
- borderRadius: BorderRadius.circular(4),
|
|
|
|
|
- ),
|
|
|
|
|
- child: Text(
|
|
|
|
|
- value,
|
|
|
|
|
- style: TextStyle(color: Colors.white, fontSize: 12),
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ decoration: BoxDecoration(color: Colors.black54, borderRadius: BorderRadius.circular(4)),
|
|
|
|
|
+ child: Text(value, style: TextStyle(color: Colors.white, fontSize: 12)),
|
|
|
);
|
|
);
|
|
|
},
|
|
},
|
|
|
);
|
|
);
|