mirror of
https://github.com/TonyJiangWJ/Auto.js.git
synced 2026-06-24 21:33:16 +08:00
修复部分内存泄露问题
This commit is contained in:
parent
6dc0d0f53f
commit
d4d96fcac9
@ -250,7 +250,6 @@ public class ScriptEngineService {
|
||||
synchronized (mEngineLifecycleCallbacks) {
|
||||
mEngineLifecycleCallbacks.add(callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void unregisterCallback(ScriptEngineManager.EngineLifecycleCallback callback) {
|
||||
|
||||
@ -49,6 +49,7 @@ public interface ScreenCaptureRequester {
|
||||
return;
|
||||
if (mCallback != null)
|
||||
mCallback.onRequestResult(Activity.RESULT_CANCELED, null);
|
||||
mCallback = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -173,6 +173,14 @@ public class Loopers implements MessageQueue.IdleHandler {
|
||||
public void recycle() {
|
||||
quitServantLooper();
|
||||
mMainMessageQueue.removeIdleHandler(this);
|
||||
mMainLooperQuitHandler = null;
|
||||
mScriptRuntime = null;
|
||||
mThreads = null;
|
||||
mTimers = null;
|
||||
mMainLooper = null;
|
||||
mServantLooper = null;
|
||||
mMainHandler = null;
|
||||
mMainMessageQueue = null;
|
||||
removeThreadLocalValue();
|
||||
}
|
||||
|
||||
|
||||
@ -2,7 +2,6 @@ package com.stardust.autojs.core.opencv;
|
||||
|
||||
import com.stardust.util.ResourceMonitor;
|
||||
|
||||
import org.mozilla.javascript.ScriptRuntime;
|
||||
import org.opencv.core.Range;
|
||||
import org.opencv.core.Rect;
|
||||
import org.opencv.core.Scalar;
|
||||
|
||||
@ -57,6 +57,7 @@ public abstract class JavaScriptEngine extends ScriptEngine.AbstractScriptEngine
|
||||
@Override
|
||||
public synchronized void destroy() {
|
||||
mRuntime.onExit();
|
||||
mExecArgv = null;
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
|
||||
@ -106,13 +106,13 @@ open class RhinoJavaScriptEngine(private val mAndroidContext: android.content.Co
|
||||
try {
|
||||
super.destroy()
|
||||
Log.d(LOG_TAG, "on destroy")
|
||||
sContextEngineMap.remove(context)
|
||||
destroySuccess = true;
|
||||
} finally {
|
||||
if (destroySuccess)
|
||||
Log.d(LOG_TAG, "destroy execute success")
|
||||
else
|
||||
Log.d(LOG_TAG, "destroy execute failed")
|
||||
sContextEngineMap.remove(context)
|
||||
Context.exit()
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,6 +29,9 @@ public class RunnableScriptExecution extends ScriptExecution.AbstractScriptExecu
|
||||
public void run() {
|
||||
ThreadCompat.currentThread().setName("ScriptThread-" + getId() + "[" + getSource() + "]");
|
||||
execute();
|
||||
|
||||
mScriptEngine = null;
|
||||
mScriptEngineManager = null;
|
||||
}
|
||||
|
||||
public Object execute() {
|
||||
|
||||
@ -427,6 +427,8 @@ public class ScriptRuntime {
|
||||
ignoresException(sensors::unregisterAll);
|
||||
ignoresException(timers::recycle);
|
||||
ignoresException(ui::recycle);
|
||||
mTopLevelScope = null;
|
||||
console.clear();
|
||||
}
|
||||
|
||||
private void ignoresException(Runnable r) {
|
||||
|
||||
@ -285,12 +285,14 @@ public class Events extends EventEmitter implements OnKeyListener, TouchObserver
|
||||
}
|
||||
if (mListeningNotification) {
|
||||
mAccessibilityBridge.getNotificationObserver().removeNotificationListener(this);
|
||||
mAccessibilityBridge.getNotificationObserver().removeToastListener(this);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2
|
||||
&& NotificationListenerService.Companion.getInstance() != null) {
|
||||
NotificationListenerService.Companion.getInstance().removeListener(this);
|
||||
}
|
||||
}
|
||||
if (mListeningToast) {
|
||||
mAccessibilityBridge.getNotificationObserver().removeToastListener(this);
|
||||
}
|
||||
if (mKeyInterceptor != null) {
|
||||
AccessibilityService service = mAccessibilityBridge.getService();
|
||||
if (service != null) {
|
||||
@ -304,12 +306,23 @@ public class Events extends EventEmitter implements OnKeyListener, TouchObserver
|
||||
service.getGestureEventDispatcher().removeListener(this);
|
||||
}
|
||||
}
|
||||
if (mLoopers != null) {
|
||||
mLoopers = null;
|
||||
}
|
||||
if (mScriptRuntime != null) {
|
||||
mScriptRuntime = null;
|
||||
}
|
||||
if (mBridges != null) {
|
||||
mBridges = null;
|
||||
removeAllListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyEvent(final int keyCode, final KeyEvent event) {
|
||||
mHandler.post(() -> {
|
||||
String keyName = KeyEvent.keyCodeToString(keyCode).substring(8).toLowerCase();
|
||||
String keyString = KeyEvent.keyCodeToString(keyCode);
|
||||
String keyName = keyString.startsWith("KEYCODE_") ? keyString.substring(8).toLowerCase() : keyString;
|
||||
emit(keyName, event);
|
||||
if (event.getAction() == KeyEvent.ACTION_DOWN) {
|
||||
emit(PREFIX_KEY_DOWN + keyName, event);
|
||||
|
||||
@ -267,6 +267,7 @@ public class Images {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && mScreenCapturer != null) {
|
||||
mScreenCapturer.release();
|
||||
}
|
||||
mScriptRuntime = null;
|
||||
}
|
||||
|
||||
public Point findImage(ImageWrapper image, ImageWrapper template) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user