debug - Debugging
[Added in Pro 8.7.0]
The Debug module provides debugging utilities such as diagnosing memory leaks and getting a detailed stack trace from an Error.
$debug.dumpHprof(file)
file{string} Dump file path
Dump the memory of the entire script process to the given file.
If you find Auto.js Pro is using a lot of memory, you can run this function to dump memory and send it to the developer, who can use the dump file to diagnose potential memory leaks.
During dumping, the entire process may freeze. Do not operate the phone to avoid dump failure or other issues. Dumping usually takes tens of seconds to a few minutes; please wait patiently.
Tips
How to send the file to the developer? You can include your script and the dump file, and email them to hybbbb1996@gmail.com. The developer will investigate and reply as soon as possible. Before reporting, it is recommended to enable memory leak detection via $debug.setMemoryLeakDetectionEnabled() to check leaks in your script first, avoid false alarms, and reduce the developer's workload.
$debug.dumpHprof('./dump.hprof');$debug.dumpAndSendHprof([file])
file{string} Dump file path (optional). Default:dump.hprof.zipunder the current directory.
Dump the process memory to file and automatically compress it into a zip file. It uses the highest compression level, which takes longer but produces a smaller file.
For more details, see $debug.dumpHprof.
$debug.getStackTrace(error)
error{Error} Exception/Error- Returns {string}
Get and return a detailed stack trace for an exception.
try {
undefined_var;
} catch(e) {
console.error($debug.getStackTrace(e));
}$debug.setMemoryLeakDetectionEnabled(enabled)
enabled{boolean} Whether to enable memory leak detection
When enabled, objects that are not manually recycled (e.g. images) will be reported in logs.
Currently detected objects include:
- Images
For example, the following code will cause a memory leak. After running for a while, you should see leak logs.
$debug.setMemoryLeakDetectionEnabled(true);
requestScreenCapture();
for (let i = 0; i < 10; i++) {
// This image should have been recycled manually
let leak = captureScreen().clone();
// Intentionally comment out recycle
// leak.recycle();
}
// Trigger GC
$debug.gc();Tip
In Auto.js Pro runtime, this feature is enabled by default; in packaged apps, it is disabled by default.
$debug.gc()
Suggest the JVM to perform garbage collection (not guaranteed).
