SuperMonster003 / AutoJs6

安卓平台 JavaScript 自动化工具 (Auto.js 二次开发项目)
https://docs.autojs6.com
Mozilla Public License 2.0
2.16k stars 653 forks source link

找图出现内存溢出问题 #198

Open taozi0001 opened 7 months ago

taozi0001 commented 7 months ago

//请求截图 log("请求截图"); requestScreenCapture(false);

log('开始步骤 8');
var target = images.read("/sdcard/脚本/安卓自动化/images/douyinfenxiang.png"); // 读取目标文件
var screen = captureScreen(); // 截取当前屏幕
images.save(screen, "/sdcard/脚本/安卓自动化/linshitupian/screen.png"); // 保存截图
var point = images.findImage(screen, target, {threshold: 0.7, region: [917, 915, 163, 972]}); // 在截图内查找目标图片的位置,相似度为80%,范围为x:917,y:915至x:1080,y:1887
if (!point) { // 没有找到 point 坐标
  log('没有找到分享控件');

} else { // 找到 point 坐标
  log('找到分享控件');

}

// 删除该步骤内被引用的控件信息 target.recycle(); // 回收目标文件占用的内存 screen.recycle(); // 回收截图占用的内存 target = null; // 清空目标文件 screen = null; // 清空截图 point = null; // 清空坐标 files.remove("/sdcard/脚本/安卓自动化/linshitupian/screen.png"); // 删除保存的截图

以上是代码,报错部分如下:

03:01:33.880/V: 开始运行 [$remote/2.js]. 03:01:33.881/D: 请求截图 03:01:34.421/D: 开始步骤 8 03:01:35.367/D: 找到分享控件 03:01:35.373/V: [$remote/2.js] 运行结束 (用时 1.491 秒)

03:01:39.370/V: 开始运行 [$remote/2.js]. 03:01:39.371/D: 请求截图 03:01:39.670/D: 开始步骤 8 03:01:40.754/D: 没有找到分享控件 03:01:40.765/V: [$remote/2.js] 运行结束 (用时 1.393 秒)

03:01:53.369/E: Failed to allocate a 48 byte allocation with 2485104 free bytes and 2426KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC.

java.lang.OutOfMemoryError: Failed to allocate a 48 byte allocation with 2485104 free bytes and 2426KB until OOM, target footprint 268435456, growth limit 268435456; giving up on allocation because <1% of heap free after GC. at java.lang.AbstractStringBuilder.(AbstractStringBuilder.java:68) at java.lang.StringBuilder.(StringBuilder.java:90) at org.mozilla.javascript.JavaMembers.reflect(JavaMembers.java:562) at org.mozilla.javascript.JavaMembers.(JavaMembers.java:63) at org.mozilla.javascript.JavaMembers_jdk11.(JavaMembers_jdk11.java:18) at org.mozilla.javascript.JavaMembers.createJavaMembers(JavaMembers.java:843) at org.mozilla.javascript.JavaMembers.lookupClass(JavaMembers.java:804) at org.mozilla.javascript.NativeJavaClass.initMembers(NativeJavaClass.java:45) at org.mozilla.javascript.NativeJavaObject.(NativeJavaObject.java:53) at org.mozilla.javascript.NativeJavaClass.(NativeJavaClass.java:39) at org.mozilla.javascript.NativeJavaClass.(NativeJavaClass.java:35) at org.mozilla.javascript.WrapFactory.wrapJavaClass(WrapFactory.java:136) at org.mozilla.javascript.NativeJavaPackage.getPkgProperty(NativeJavaPackage.java:115) at org.mozilla.javascript.NativeJavaPackage.get(NativeJavaPackage.java:72) at org.mozilla.javascript.ScriptableObject.getProperty(ScriptableObject.java:2024) at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1706) at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1701) at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1549) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1051) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:87) at org.mozilla.javascript.ArrowFunction.call(ArrowFunction.java:40) at org.mozilla.javascript.NativeArray.iterativeMethod(NativeArray.java:2031) at org.mozilla.javascript.NativeArray.execIdCall(NativeArray.java:437) at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:84) at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1869) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1051) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:87) at org.mozilla.javascript.ArrowFunction.call(ArrowFunction.java:40) at org.mozilla.javascript.NativeArray.iterativeMethod(NativeArray.java:2031) at org.mozilla.javascript.NativeArray.execIdCall(NativeArray.java:437) at org.mozilla.javascript.IdFunctionObject.call(IdFunctionObject.java:84) at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1869) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1051) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:87) at org.mozilla.javascript.ArrowFunction.call(ArrowFunction.java:40) at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1869) at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:1051) at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:87) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:383) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3941) at org.mozilla.javascript.Context.callFunctionWithContinuations(Context.java:1253) at org.mozilla.javascript.Context.executeScriptWithContinuations(Context.java:1221) at org.autojs.autojs.engine.RhinoJavaScriptEngine.init(RhinoJavaScriptEngine.kt:102) at org.autojs.autojs.engine.LoopBasedJavaScriptEngine.init(LoopBasedJavaScriptEngine.java:112) at org.autojs.autojs.execution.RunnableScriptExecution.prepare(RunnableScriptExecution.java:65) at org.autojs.autojs.execution.RunnableScriptExecution.execute(RunnableScriptExecution.java:39) at org.autojs.autojs.execution.RunnableScriptExecution.execute(RunnableScriptExecution.java:34) at org.autojs.autojs.execution.RunnableScriptExecution.run(RunnableScriptExecution.java:28) at java.lang.Thread.run(Thread.java:920)

SuperMonster003 commented 2 months ago

下一版本将尝试优化 OOM 问题, 但效果可能有限, 新版发布后, 如问题依然存在, 可继续反馈.