[Android] Assert refcount == 0 on finalize
Romain Vimont
git at videolan.org
Wed Jul 18 10:02:39 CEST 2018
vlc-android | branch: master | Romain Vimont <rom1v at videolabs.io> | Tue Jul 17 19:45:32 2018 +0200| [afea771c071cb34e32730bfc94a51a1323985a10] | committer: Geoffrey Métais
Assert refcount == 0 on finalize
VLCObject manages a refcount to release native resources. If the Java
object is finalized, this is an error if the refcount is not 0
(native resources have not been released as expected).
Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>
> https://code.videolan.org/videolan/vlc-android/commit/afea771c071cb34e32730bfc94a51a1323985a10
---
libvlc/src/org/videolan/libvlc/VLCObject.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/libvlc/src/org/videolan/libvlc/VLCObject.java b/libvlc/src/org/videolan/libvlc/VLCObject.java
index a22195127..1144434cf 100644
--- a/libvlc/src/org/videolan/libvlc/VLCObject.java
+++ b/libvlc/src/org/videolan/libvlc/VLCObject.java
@@ -91,6 +91,12 @@ abstract class VLCObject<T extends VLCEvent> {
}
}
+ @Override
+ protected synchronized void finalize() {
+ if (!isReleased())
+ throw new AssertionError("VLCObject (" + getClass().getName() + ") finalized but not natively released (" + mNativeRefCount + " refs)");
+ }
+
/**
* Set an event listener.
* Events are sent via the android main thread.
More information about the Android
mailing list