Re: Android Strict Mode complaining HttpURLConnection is never released/closed

3,260 views
Skip to first unread message

Eric Leichtenschlag

unread,
Apr 5, 2013, 9:06:07 PM4/5/13
to google-adm...@googlegroups.com
We believe this is an issue looks like an implementation issue with HttpURLConnection. The SDK calls HttpURLConnection.disconnect() in a finally block when it's finished with the connection, so it should always clean itself up properly. I don't see an 'end' method on this class.


On Wed, Apr 3, 2013 at 6:58 AM, Jonathan Caryl <jonathan.car...@googlemail.com> wrote:
Did you ever find an answer to your question? I'm seeing the same Throwable: Explicit termination method 'end' not called when trying to use HttpURLConnection.getResponseCode in my own code, which makes me wonder whether it's a bug.

Jonathan


On Monday, 24 September 2012 21:27:14 UTC+1, Roberto Andrade wrote:
I get the following exception when running my Android app that used Google AdMob SDK for ad retrieval as soon as the rendering of my activity completes if I'm running the app with Strict Mode on to detect any leak of any kind:

09-24 16:21:56.724: E/StrictMode(13387): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
09-24 16:21:56.724: E/StrictMode(13387): java.lang.Throwable: Explicit termination method 'end' not called
09-24 16:21:56.724: E/StrictMode(13387): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
09-24 16:21:56.724: E/StrictMode(13387): at java.util.zip.Inflater.<init>(Inflater.java:82)
09-24 16:21:56.724: E/StrictMode(13387): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
09-24 16:21:56.724: E/StrictMode(13387): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
09-24 16:21:56.724: E/StrictMode(13387): at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:512)
09-24 16:21:56.724: E/StrictMode(13387): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:805)
09-24 16:21:56.724: E/StrictMode(13387): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
09-24 16:21:56.724: E/StrictMode(13387): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:479)
09-24 16:21:56.724: E/StrictMode(13387): at com.google.ads.internal.f.b(SourceFile:429)
09-24 16:21:56.724: E/StrictMode(13387): at com.google.ads.internal.f.run(SourceFile:399)
09-24 16:21:56.724: E/StrictMode(13387): at java.lang.Thread.run(Thread.java:856)
09-24 16:21:56.724: W/System.err(13387): StrictMode VmPolicy violation with POLICY_DEATH; shutting down.

Given this is all done by the internal class F I'm not sure how to work around it to avoid resource contention issues while using this product. Any tips?

--
 
---
You received this message because you are subscribed to the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
  

Gicci

unread,
Apr 15, 2013, 5:52:53 PM4/15/13
to google-adm...@googlegroups.com
I get similar warnings as well:

04-15 23:23:57.971: E/StrictMode(30455): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
04-15 23:23:57.971: E/StrictMode(30455): java.lang.Throwable: Explicit termination method 'end' not called
04-15 23:23:57.971: E/StrictMode(30455):     at dalvik.system.CloseGuard.open(CloseGuard.java:184)
04-15 23:23:57.971: E/StrictMode(30455):     at java.util.zip.Inflater.<init>(Inflater.java:82)
04-15 23:23:57.971: E/StrictMode(30455):     at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
04-15 23:23:57.971: E/StrictMode(30455):     at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
04-15 23:23:57.971: E/StrictMode(30455):     at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:528)
04-15 23:23:57.971: E/StrictMode(30455):     at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:836)
04-15 23:23:57.971: E/StrictMode(30455):     at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
04-15 23:23:57.971: E/StrictMode(30455):     at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
04-15 23:23:57.971: E/StrictMode(30455):     at com.google.ads.internal.f.b(SourceFile:472)
04-15 23:23:57.971: E/StrictMode(30455):     at com.google.ads.internal.f.run(SourceFile:442)
04-15 23:23:57.971: E/StrictMode(30455):     at java.lang.Thread.run(Thread.java:856)
04-15 23:23:58.026: E/StrictMode(30455): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
04-15 23:23:58.026: E/StrictMode(30455): java.lang.Throwable: Explicit termination method 'close' not called
04-15 23:23:58.026: E/StrictMode(30455):     at dalvik.system.CloseGuard.open(CloseGuard.java:184)
04-15 23:23:58.026: E/StrictMode(30455):     at android.content.ContentResolver$CursorWrapperInner.<init>(ContentResolver.java:1837)
04-15 23:23:58.026: E/StrictMode(30455):     at android.content.ContentResolver.query(ContentResolver.java:394)
04-15 23:23:58.026: E/StrictMode(30455):     at android.content.ContentResolver.query(ContentResolver.java:315)
04-15 23:23:58.026: E/StrictMode(30455):     at com.google.ads.as$a.run(SourceFile:75)
04-15 23:23:58.026: E/StrictMode(30455):     at java.lang.Thread.run(Thread.java:856)
04-15 23:23:58.036: E/StrictMode(30455): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
04-15 23:23:58.036: E/StrictMode(30455): java.lang.Throwable: Explicit termination method 'close' not called
04-15 23:23:58.036: E/StrictMode(30455):     at dalvik.system.CloseGuard.open(CloseGuard.java:184)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.CursorWindow.<init>(CursorWindow.java:141)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.CursorWindow.<init>(CursorWindow.java:41)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:683)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.CursorWindow.newFromParcel(CursorWindow.java:694)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.BulkCursorProxy.getWindow(BulkCursorNative.java:168)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.BulkCursorToCursorAdaptor.onMove(BulkCursorToCursorAdaptor.java:83)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:213)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236)
04-15 23:23:58.036: E/StrictMode(30455):     at android.database.CursorWrapper.moveToFirst(CursorWrapper.java:65)
04-15 23:23:58.036: E/StrictMode(30455):     at com.google.ads.as$a.run(SourceFile:79)
04-15 23:23:58.036: E/StrictMode(30455):     at java.lang.Thread.run(Thread.java:856)

Could it be that you just need to close the stream you used to read the data after the disconnect, like the examples do with the super class URLConnection?

/Giuseppe
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.

Eric Leichtenschlag

unread,
Apr 16, 2013, 6:30:48 PM4/16/13
to google-adm...@googlegroups.com
Possibly, but then why wouldn't the HttpURLConnection explicitly close the input stream as well?

Does this happen every time? If so, can you provide a small sample app that can reproduce the issue (and what device it happens on)? Maybe I'm missing some setting, but I was not able to reproduce the issue on a Galaxy Nexus when using "Strict Mode Enabled - Flash screen when apps to long operations on main thread."

Thanks,
Eric


To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.

Gicci

unread,
Apr 16, 2013, 7:05:10 PM4/16/13
to google-adm...@googlegroups.com
We should be in the mind of who coded that, but anyway it states that you can close or reuse the resources, so I guess that this is the way it is designed to work...

Tested a few times, always with the same errors. Galaxy S2, 4.1.2. Will try to strip all my code, but not in the next few days, I am quite busy.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
 
  

Eric Leichtenschlag

unread,
Apr 17, 2013, 8:53:35 PM4/17/13
to google-adm...@googlegroups.com
I wasn't able to reproduce on a Galaxy S2.


To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.

nagamatu

unread,
Jul 1, 2013, 9:35:42 PM7/1/13
to google-adm...@googlegroups.com
I encountered the same problem with AdMob 6.2.1 or 6.4.1 and Android 4.1.2 emulator.

E/StrictMode( 1096): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
E/StrictMode( 1096): java.lang.Throwable: Explicit termination method 'end' not called
E/StrictMode( 1096): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
E/StrictMode( 1096): at java.util.zip.Inflater.<init>(Inflater.java:82)
E/StrictMode( 1096): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
E/StrictMode( 1096): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
E/StrictMode( 1096): at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:528)
E/StrictMode( 1096): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:836)
E/StrictMode( 1096): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
E/StrictMode( 1096): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
E/StrictMode( 1096): at com.google.ads.internal.f.b(SourceFile:490)
E/StrictMode( 1096): at com.google.ads.internal.f.run(SourceFile:460)
E/StrictMode( 1096): at java.lang.Thread.run(Thread.java:856)
W/System.err( 1096): StrictMode VmPolicy violation with POLICY_DEATH; shutting down.
I/Process ( 1096): Sending signal. PID: 1096 SIG: 9


2013年4月18日木曜日 9時53分35秒 UTC+9 Eric Leichtenschlag:

DK2

unread,
Jul 30, 2013, 8:11:04 AM7/30/13
to google-adm...@googlegroups.com
Hi Eric, 

I encounter and can reproduce the same problem with SDK 6.4.1 on a Galaxy S2 with Android version 4.1.2, and on a Galaxy Tab 10.1 with Android 4.0.3 but not on an Sony Ericsson Xperia with 2.3.4. The error seems to only appear on more recent Android releases and can be seen in emulator too.  

The log trace below repeats for every banner ad loaded indefinitely while the app displays an Activity with banner visible.

NOTE: I enable strict mode to detect all issues programatically not via device via StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll().penaltyLog();

07-30 13:43:36.718: E/StrictMode(28335): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-30 13:43:36.718: E/StrictMode(28335): java.lang.Throwable: Explicit termination method 'close' not called
07-30 13:43:36.718: E/StrictMode(28335): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-30 13:43:36.718: E/StrictMode(28335): at android.content.ContentResolver$CursorWrapperInner.<init>(ContentResolver.java:1837)
07-30 13:43:36.718: E/StrictMode(28335): at android.content.ContentResolver.query(ContentResolver.java:394)
07-30 13:43:36.718: E/StrictMode(28335): at android.content.ContentResolver.query(ContentResolver.java:315)
07-30 13:43:36.718: E/StrictMode(28335): at com.google.ads.at$a.run(SourceFile:75)
07-30 13:43:36.718: E/StrictMode(28335): at java.lang.Thread.run(Thread.java:856)

07-30 13:43:36.723: E/StrictMode(28335): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-30 13:43:36.723: E/StrictMode(28335): java.lang.Throwable: Explicit termination method 'close' not called
07-30 13:43:36.723: E/StrictMode(28335): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.CursorWindow.<init>(CursorWindow.java:141)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.CursorWindow.<init>(CursorWindow.java:41)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:683)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.CursorWindow.newFromParcel(CursorWindow.java:694)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.BulkCursorProxy.getWindow(BulkCursorNative.java:168)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.BulkCursorToCursorAdaptor.onMove(BulkCursorToCursorAdaptor.java:83)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:213)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236)
07-30 13:43:36.723: E/StrictMode(28335): at android.database.CursorWrapper.moveToFirst(CursorWrapper.java:65)
07-30 13:43:36.723: E/StrictMode(28335): at com.google.ads.at$a.run(SourceFile:79)
07-30 13:43:36.723: E/StrictMode(28335): at java.lang.Thread.run(Thread.java:856)

07-30 13:43:37.773: E/StrictMode(28335): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-30 13:43:37.773: E/StrictMode(28335): java.lang.Throwable: Explicit termination method 'end' not called
07-30 13:43:37.773: E/StrictMode(28335): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-30 13:43:37.773: E/StrictMode(28335): at java.util.zip.Inflater.<init>(Inflater.java:82)
07-30 13:43:37.773: E/StrictMode(28335): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
07-30 13:43:37.773: E/StrictMode(28335): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
07-30 13:43:37.773: E/StrictMode(28335): at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:528)
07-30 13:43:37.773: E/StrictMode(28335): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:836)
07-30 13:43:37.773: E/StrictMode(28335): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
07-30 13:43:37.773: E/StrictMode(28335): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
07-30 13:43:37.773: E/StrictMode(28335): at com.google.ads.internal.f.b(SourceFile:490)
07-30 13:43:37.773: E/StrictMode(28335): at com.google.ads.internal.f.run(SourceFile:460)
07-30 13:43:37.773: E/StrictMode(28335): at java.lang.Thread.run(Thread.java:856)

and repeating when displaying next banner ad...

07-30 13:43:49.888: E/StrictMode(28335): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-30 13:43:49.888: E/StrictMode(28335): java.lang.Throwable: Explicit termination method 'close' not called
07-30 13:43:49.888: E/StrictMode(28335): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-30 13:43:49.888: E/StrictMode(28335): at android.content.ContentResolver$CursorWrapperInner.<init>(ContentResolver.java:1837)
07-30 13:43:49.888: E/StrictMode(28335): at android.content.ContentResolver.query(ContentResolver.java:394)
07-30 13:43:49.888: E/StrictMode(28335): at android.content.ContentResolver.query(ContentResolver.java:315)
07-30 13:43:49.888: E/StrictMode(28335): at com.google.ads.at$a.run(SourceFile:75)
07-30 13:43:49.888: E/StrictMode(28335): at java.lang.Thread.run(Thread.java:856)

07-30 13:43:49.888: E/StrictMode(28335): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-30 13:43:49.888: E/StrictMode(28335): java.lang.Throwable: Explicit termination method 'close' not called
07-30 13:43:49.888: E/StrictMode(28335): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.CursorWindow.<init>(CursorWindow.java:141)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.CursorWindow.<init>(CursorWindow.java:41)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:685)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.CursorWindow$1.createFromParcel(CursorWindow.java:683)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.CursorWindow.newFromParcel(CursorWindow.java:694)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.BulkCursorProxy.getWindow(BulkCursorNative.java:168)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.BulkCursorToCursorAdaptor.onMove(BulkCursorToCursorAdaptor.java:83)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.AbstractCursor.moveToPosition(AbstractCursor.java:213)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.AbstractCursor.moveToFirst(AbstractCursor.java:236)
07-30 13:43:49.888: E/StrictMode(28335): at android.database.CursorWrapper.moveToFirst(CursorWrapper.java:65)
07-30 13:43:49.888: E/StrictMode(28335): at com.google.ads.at$a.run(SourceFile:79)
07-30 13:43:49.888: E/StrictMode(28335): at java.lang.Thread.run(Thread.java:856)

07-30 13:43:49.893: E/StrictMode(28335): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
07-30 13:43:49.893: E/StrictMode(28335): java.lang.Throwable: Explicit termination method 'end' not called
07-30 13:43:49.893: E/StrictMode(28335): at dalvik.system.CloseGuard.open(CloseGuard.java:184)
07-30 13:43:49.893: E/StrictMode(28335): at java.util.zip.Inflater.<init>(Inflater.java:82)
07-30 13:43:49.893: E/StrictMode(28335): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
07-30 13:43:49.893: E/StrictMode(28335): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
07-30 13:43:49.893: E/StrictMode(28335): at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:528)
07-30 13:43:49.893: E/StrictMode(28335): at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:836)
07-30 13:43:49.893: E/StrictMode(28335): at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
07-30 13:43:49.893: E/StrictMode(28335): at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
07-30 13:43:49.893: E/StrictMode(28335): at com.google.ads.internal.f.b(SourceFile:490)
07-30 13:43:49.893: E/StrictMode(28335): at com.google.ads.internal.f.run(SourceFile:460)
07-30 13:43:49.893: E/StrictMode(28335): at java.lang.Thread.run(Thread.java:856)

Reply all
Reply to author
Forward
0 new messages