Memory leak when pressing back

287 views
Skip to first unread message

Attila Szász

unread,
Sep 27, 2011, 3:02:05 PM9/27/11
to VimeoDroid
Hi,

I have just noticed that VimeoDroid does not close the
AndroidHttpClient when pressing the Back button while playing a video,
which could lead to memory leaks?

Here's the extract from logcat:

09-27 19:47:59.238 E/VPlayer ( 1464): CHARSET SUB FILE OPEN FAILED
09-27 19:47:59.248 E/VPlayer ( 1464): CHARSET SUB FILE OPEN FAILED
09-27 19:49:10.877 E/AndroidHttpClient( 1448): Leak found
09-27 19:49:10.877 E/AndroidHttpClient( 1448):
java.lang.IllegalStateException: AndroidHttpClient created and never
closed
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
android.net.http.AndroidHttpClient.<init>(AndroidHttpClient.java:152)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:
138)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:
147)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
com.makotosan.vimeodroid.vimeo.Methods.getHttpResponse(Methods.java:
149)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
com.makotosan.vimeodroid.vimeo.Methods.getHttpResponse(Methods.java:
162)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
com.makotosan.vimeodroid.vimeo.Methods.getContentType(Methods.java:
138)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
com.makotosan.vimeodroid.VideoPlayerActivity
$1.run(VideoPlayerActivity.java:35)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): Leak found
09-27 19:49:10.877 E/AndroidHttpClient( 1448):
java.lang.IllegalStateException: AndroidHttpClient created and never
closed
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
android.net.http.AndroidHttpClient.<init>(AndroidHttpClient.java:152)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:
138)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:
147)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
com.makotosan.vimeodroid.vimeo.Methods.getRedirectedUri(Methods.java:
242)
09-27 19:49:10.877 E/AndroidHttpClient( 1448): at
com.makotosan.vimeodroid.VideoPlayerActivity
$1.run(VideoPlayerActivity.java:34)

Makoto Schoppert

unread,
Sep 28, 2011, 10:16:16 PM9/28/11
to VimeoDroid
Thank you!

That's very helpful!

I am going to take a look into this now.

Makoto Schoppert

unread,
Sep 28, 2011, 11:20:51 PM9/28/11
to VimeoDroid
It was a result of me using the generic HttpClient class throughout,
even though I may be instantiating an instance of the
AndroidHttpClient if the device's SDK supports it (Froyo and newer).
For older devices, I use the DefaultHttpClient.

One thing about using the AndroidHttpClient is that you have to
explicitly close() the client to release resources which I wasn't
doing. I added a check to see if client is an instance of
AndroidHttpClient, and if so, close() it.

Here's the documentation on it if anybody is curious:
http://developer.android.com/reference/android/net/http/AndroidHttpClient.html#close()


On Sep 27, 3:02 pm, Attila Szász <tilus...@gmail.com> wrote:

Attila Szász

unread,
Sep 29, 2011, 11:21:20 AM9/29/11
to VimeoDroid
Prompt fix, great and thanks for the details! I just got the update
through the Market.


On Sep 29, 4:20 am, Makoto Schoppert <makoto...@gmail.com> wrote:
> It was a result of me using the generic HttpClient class throughout,
> even though I may be instantiating an instance of the
> AndroidHttpClient if the device's SDK supports it (Froyo and newer).
> For older devices, I use the DefaultHttpClient.
>
> One thing about using the AndroidHttpClient is that you have to
> explicitly close() the client to release resources which I wasn't
> doing.  I added a check to see if client is an instance of
> AndroidHttpClient, and if so, close() it.
>
> Here's the documentation on it if anybody is curious:http://developer.android.com/reference/android/net/http/AndroidHttpCl...()

Attila Szász

unread,
Sep 29, 2011, 11:57:24 AM9/29/11
to VimeoDroid
Makoto,

Since I am at this thread, I'll post this here as a suggestion for
improvement:
there are often cases when I tap on a video to play and for a good
amount of seconds nothing seem to happen... I think it happens mostly
when there is trouble with the network connection.
Could you add perhaps some some of those "Toast" notifications telling
what's happening in the background? E.g. "Connecting to vimeo...",
etc.

Cheers in advance.


On Sep 29, 4:20 am, Makoto Schoppert <makoto...@gmail.com> wrote:
> It was a result of me using the generic HttpClient class throughout,
> even though I may be instantiating an instance of the
> AndroidHttpClient if the device's SDK supports it (Froyo and newer).
> For older devices, I use the DefaultHttpClient.
>
> One thing about using the AndroidHttpClient is that you have to
> explicitly close() the client to release resources which I wasn't
> doing.  I added a check to see if client is an instance of
> AndroidHttpClient, and if so, close() it.
>
> Here's the documentation on it if anybody is curious:http://developer.android.com/reference/android/net/http/AndroidHttpCl...()

Makoto Schoppert

unread,
Sep 29, 2011, 12:04:24 PM9/29/11
to VimeoDroid
I was actually thinking about doing that. While playing around with
it last night, I did notice how it does take a couple seconds to do
something. It's because it has to do some "special" stuff in order to
get the mp4 URL of the video. Vimeo doesn't provide a way through
their API to get to the video URL directly.

In order to get the video URL, there are a few steps that it has to
take and parse some XML which takes a couple of seconds. I'll have it
show a progress dialog or a toast notification during this process so
that the user knows something is happening.

Attila Szász

unread,
Sep 30, 2011, 7:01:43 AM9/30/11
to VimeoDroid
That would be great, cheers.
Reply all
Reply to author
Forward
0 new messages