W/system: A Resource Failed To Call Release
Solution 1:
The answer from @guest works, but you can achieve the exact same thing without resorting to reflection using Strict Mode. Specifically, something like:
StrictMode.setVmPolicy(new VmPolicy.Builder()
.detectLeakedClosableObjects()
.penaltyLog()
.build());
In general, strict mode can do much more for you though (see link above to doc), and all you need to do for a default setup is:
StrictMode.enableDefaults(); # <-- This includes warning on leaked closeables
To enable strict mode "as soon as possible" you can add either of the above code options to the constructor of your application class, e.g.:
publicclassMyAppextendsApplication {
publicMyApp() {
if(BuildConfig.DEBUG)
StrictMode.enableDefaults();
}
}
Note that in addition to just creating the class above, you need to tell Android that you have created a custom application class in the AndroidManifest.xml
(so that an instance of it gets created when your application process starts, instead of Android creating the default Application
class). You need to add/modify the android:name
attribute of the <application>
tag to point to the fully resolved package path of your custom application class (MyApp
in this case):
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="com.example.app.MyApp" <-- IMPORTANT PART: ADAPT FOR YOUR ACTUAL PROJECT
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
Solution 2:
This message comes from dalvik.system.CloseGuard
. When debugging, you can set it up to create stack traces as you create resources, so that you can track down what objects aren't being closed.
It's not part of the framework API, so I'm using reflection to turn that on:
try {
Class.forName("dalvik.system.CloseGuard")
.getMethod("setEnabled", boolean.class)
.invoke(null, true);
} catch (ReflectiveOperationException e) {
thrownewRuntimeException(e);
}
Solution 3:
I don't think that you can get any more information out of Logcat.
The memory view of the Android Profiler is probably a good place to start. Looking at it while using your app should give you an idea of what actions cause memory to be allocated and not released. You can also select sections from the timeline and drill down to specific allocations by class.
Alternatively LeakCanary is a great library to detect memory leaks.
Solution 4:
Fixed it by removing a function call that called itself through another function thereby making an infinite loop of calls to itself
Solution 5:
Late answer, but it may be useful to someone else:
I faced the same error, but I forgot I had my VPN running in the background. Disconnecting the VPN did the trick for me. This is to say it may be due to resources unrelated to your app or IDE you may want to check, like an antivirus, VPN, etc.
Post a Comment for "W/system: A Resource Failed To Call Release"