Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leak found: AndroidHttpClient created and never closed

I don't really instantiate an AndroidHttpClient anywhere in my code, but I do start a recognizer intent, which yields this exception at some point when my application runs:

Leak found
java.lang.IllegalStateException: AndroidHttpClient created and never closed
    at android.net.http.AndroidHttpClient.<init>(AndroidHttpClient.java:152)
    at android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:138)
    at com.google.android.voicesearch.speechservice.SpeechServiceHttpClient.<init>(SpeechServiceHttpClient.java:59)
    at com.google.android.voicesearch.speechservice.ServerConnectorImpl.<init>(ServerConnectorImpl.java:85)
    at com.google.android.voicesearch.VoiceSearchContainerImpl.createRecognitionController(VoiceSearchContainerImpl.java:83)
    at com.google.android.voicesearch.GoogleRecognitionService.onCreate(GoogleRecognitionService.java:65)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2066)
    at android.app.ActivityThread.access$2500(ActivityThread.java:123)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:130)
    at android.app.ActivityThread.main(ActivityThread.java:3835)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
    at dalvik.system.NativeStart.main(Native Method)

Assuming the bug is not in Android's code but in mine, this leaked resource could have been created only in one of the following:

  1. SpeechRecognizer.createSpeechRecognizer()
  2. new RecognitionListener()
  3. new Intent(SpeechRecognizer.RESULTS_RECOGNITION)
  4. SpeechRecognizer.startListening(recognizerIntent)

But how do I know which one?

like image 424
srf Avatar asked Oct 25 '11 14:10

srf


2 Answers

Assuming the bug is not in Android's code but in mine

The leak is in com.google.android.voicesearch, which is not your code.

If you can create a small sample project that demonstrates this leak, we can get an issue over to Google and hope that they will address it.

like image 179
CommonsWare Avatar answered Sep 17 '22 00:09

CommonsWare


Why do you assume it's not in Android? SpeechRecognizer and RecognitionListener are in ASOP, so you can check (it's not there). Most probably SpeechServiceHttpClient uses an AndroidHttpClient internally. There is not much you can do but check you are calling all finalizer methods, if any (close(), shutdown(), etc), of the framework classes you are using.

like image 26
Nikolay Elenkov Avatar answered Sep 17 '22 00:09

Nikolay Elenkov