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

7

42

I am getting this message in logcat

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

Where do I look for the leak and what does it mean by " See java.io.Closeable".

Hewett answered 28/8, 2014 at 8:18 Comment(0)
F
16

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).

Facility answered 28/8, 2014 at 8:26 Comment(0)
P
8

For me the problem happened because I was overriding the method onBackPressed() without calling the super()

@Override
public void onBackPressed() {
    //some coding here
    super.onBackPressed();
}
Pastoralize answered 26/6, 2015 at 8:24 Comment(0)
C
6

if you see something like:

10-12 16:46:44.719 2710-2719/? E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
10-12 16:46:44.719 2710-2719/? E/StrictMode: java.lang.Throwable: Explicit termination method 'end' not called
10-12 16:46:44.719 2710-2719/? E/StrictMode:     at dalvik.system.CloseGuard.open(CloseGuard.java:184)
10-12 16:46:44.719 2710-2719/? E/StrictMode:     at java.util.zip.Inflater.<init>(Inflater.java:82)
10-12 16:46:44.719 2710-2719/? E/StrictMode:     at com.android.okio.GzipSource.<init>(GzipSource.java:57)
10-12 16:46:44.719 2710-2719/? E/StrictMode:     at com.android.okhttp.internal.http.HttpEngine.initContentStream(HttpEngine.java:490)

in your stacktrace, there is a known bug in older versions of okhttp that you can avoid by forcing the use of a newer version in your gradle file.

compile 'com.squareup.okhttp3:okhttp:3.2.0'

that solved a very similar problem for me at least.

Caucasoid answered 2/5, 2016 at 9:45 Comment(2)
I'm using 3.10.0 but I still have this problem. any comment?Sag
This error occurs on Emulator with Android api 27, but not on api 29.Lyndes
I
3

The same error message also shows up when there is a problem in AndroidManifest.xml. For me, the <activity> tag accidentally went out of <application>

This is correct:

<application ... >
    ...
    <activity ... />
</application>

This will result in "A resource was acquired at attached stack trace but never released" when starting the activity:

<application ... >
    ...
</application>

<activity ... />
Irena answered 16/2, 2015 at 10:0 Comment(0)
P
1

This has happened to me while launching a second activity from another activity when I did not declare the second activity in Application.mk.

Phillips answered 21/6, 2015 at 13:44 Comment(0)
M
1

For me, it seems that is something related to emulator, as it disappeared by changing to another emulator. you can test on real device.

Magic answered 21/7, 2021 at 3:55 Comment(0)
M
-4

My error was caused by enabling the strict mode. When I was doing redeployments on a test phone using adb, some resources were not closed correctly.

I "fixed" the error by removing deathPenalty from the strict mode:

            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
//                    .penaltyDeath()
                    .build());
Maida answered 3/2, 2017 at 7:11 Comment(4)
This is not a proper fix if the quote-unquote wasn't noticed.Pierpont
Best fix ever :DSelfcontained
I kind of agree with vanomart. Maybe this problem doesn't always kill the app? But for me it did and eventually I wanted to move on since I couldn't find the source. I don't get what the benefit is with the penaltyDeath() except that this error wont go unnoticed, but what I do right now is watch all the stacktrace for errors so it makes no sense that the app has to die for me. I would of course prefer to know what causes it but I guess it is different sources of the problem for everybody?Indre
You got down voted because that just hides problem, it doesn't fix the fact you opened resources that get didn't closed.Montserrat

© 2022 - 2024 — McMap. All rights reserved.