You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
prevent reference cycles between Java and native objects
This commit is contained in:
@@ -18,6 +18,7 @@ public class MediaCodec {
|
||||
private long native_codec;
|
||||
private boolean outputFormatSet = false;
|
||||
private MediaFormat mediaFormat;
|
||||
private boolean isReleased = false;
|
||||
|
||||
private Queue<Integer> freeOutputBuffers;
|
||||
private Queue<Integer> queuedInputBuffers;
|
||||
@@ -148,6 +149,19 @@ public class MediaCodec {
|
||||
public void release() {
|
||||
System.out.println("MediaCodec.release(): codecName=" + codecName);
|
||||
native_release(native_codec);
|
||||
isReleased = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void finalize() throws Throwable {
|
||||
try {
|
||||
super.finalize();
|
||||
} finally {
|
||||
if (!isReleased) {
|
||||
release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private native long native_constructor(String codecName);
|
||||
|
||||
Reference in New Issue
Block a user