kkevsekk1 / AutoX

A UiAutomator on android, does not need root access(安卓平台上的JavaScript自动化工具)
Other
6.82k stars 1.67k forks source link

长时间使用内存占用大,尤其是Paddle.orc功能 #678

Closed wanZzz6 closed 7 months ago

wanZzz6 commented 9 months ago
  1. Autox.js 版本:635

  2. Autox.js 下载渠道:https://github.com/kkevsekk1/AutoX/releases

  3. Android 版本:鸿蒙4.0

  4. Android 机型:华为Mate 30

  5. Android 系统类别:鸿蒙4.0

  6. VSCODE Autox.js 扩展版本(可选,如果是连接电脑的问题需要填):

  7. 问题描述:autoX 脚本(未打包)运行了几个小时后发现内存占用过大,专门针对paddle.ocr() 方法进行了测试,截取一张屏幕图片,反复进行paddle.ocr 识别几百次,发现内存占用越来越大,达到一定峰值(800M左右)后就不再上涨了。 又用同样的方法测试了MLkIT OCR,没有发现内存占用过大的问题(只有200M左右)。 我看针对内存占用过大问题也有几个相关的 issue,对此有什么好的解决方案或建议么?

  8. 报错日志(可选):

  9. 屏幕截图(可选): (PS,这个图是我某游戏脚本运行一天后的情况,不仅仅有OCR)

    image-20230923181320005

最后附上我的内存检测代码

/**
 * 获取设备当前内存信息
 */
function getDeviceMemoryInfo() {
  const activityManager = context.getSystemService(context.ACTIVITY_SERVICE);
  const totalInfo = new android.app.ActivityManager.MemoryInfo();
  activityManager.getMemoryInfo(totalInfo);

  // 单位字节,再除以 1024 转为 MB。
  const totalMemory = totalInfo.totalMem / (1024 * 1024);
  const availableMemory = totalInfo.availMem / (1024 * 1024);
  const usedMemory = totalMemory - availableMemory;

  // 获取当前应用程序的进程ID
  const packageName = context.getPackageName();
  const pid = android.os.Process.myPid();
  const memoryInfo = activityManager.getProcessMemoryInfo([pid]);
  // 获取应用程序使用的内存大小, 单位KB,再除以 1024 转为 MB。
  const autoJsUsage = memoryInfo[0].getTotalPss() / 1024;

  // 保留2位小数
  return {
    total: totalMemory.toFixed(2), // 总内存
    used: usedMemory.toFixed(2), //已使用
    available: availableMemory.toFixed(2), // 空闲
    currentPackageName: packageName, // 当前应用包名
    currentPackageUsed: autoJsUsage.toFixed(2) // 当前应用内存占用
  };
}

const memoryInfo = getDeviceMemoryInfo();
console.log(
  `Total: ${memoryInfo.total}MB | Used: ${memoryInfo.used}MB | AutoXjs Used:${memoryInfo.currentPackageUsed}MB | Available: ${memoryInfo.available}MB`
);
github-actions[bot] commented 7 months ago

此lssue由于长期未活动已被自动关闭,如问题任然存在,请重新打开lssue