A Resource Was Acquired at Attached Stack Trace But Never Released. See Java.Io.Closeable for Information on Avoiding Resource Leaks

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks

That means you have opened something but never close them.Closable have a method close which you must call to release the resources associated with the component when you no longer need it.

To look for the leak, you can try MAT, I often use it to find memory leaks(static data holding a reference to Activity, etc).

Android StrictMode Policy: A resource was acquired at attached stack trace but never released Error

When it comes to ExifInterface, always use one from a library, for a few reasons:

  • Devices older than Android 7.0 may have a security flaw in the framework copy of ExifInterface

  • The API changed over the years, and the library will give you a consistent API and functionality regardless of Android version

  • The framework team does not always test their code with StrictMode enabled, and device manufacturers make similar mistakes

A resource was acquired at attached stack trace but never released. memory leak

StrictMode only reports failures to release objects that are explicitly monitored by StrictMode. It doesn't fire because you fail to release a string from JNI. The object allocated at the point in the code indicated by the stack trace needs to be released with an explicit close() call before the last reference to it is dropped. If the object is discarded and finalized before it is closed, the system reports an error.

The method you're calling may or may not have anything to do with the failing object -- it may simply be doing allocations that cause the GC to happen sooner, so your app reports the error immediately rather than doing so later.

Including more of the logcat output in your question may be useful here. The strict mode code is typically configured to issue warnings... if your app is actually crashing the problem may not be related to the failure to close the resource.

One possible problem with your code is misuse of b. You're passing it to GetMethodID(), which takes a jclass as its second argument; since that apparently works, I would expect 'b' to be a class. This will be the case if the HelloJNI method were declared static in the Java code. (You call GetObjectClass(a,b), but ignore the result.) That being the case, passing 'b' as the second argument to CallVoidMethod() is probably wrong, and will lead to a failure.

Further, as noted in another answer, you cannot pass a C string or char* when a jstring is required. "FROM JNI" must be converted to a jstring with NewStringUTF. The compiler should warn about that.

With CheckJNI enabled I would expect a JNI error to be reported, which does kill the app.



Related Topics



Leave a reply



Submit