callback/callback-android — Issue #37: PhoneGap Android JSAlerts may have a memory leak
Author: macdonst
Created: 2011-11-25 19:55:50+00:00
State: open

This was discovered on a client project, and is intermittent. I wrote it off as a device issue until I ran into the same issue today on a Nexus S running CyanogenMod. Here's the issue in question!

```
E/WindowManager( 4255): android.view.WindowLeaked: Activity (removed for confidentiality) has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@40586158 that was originally added here
E/WindowManager( 4255):	at android.view.ViewRoot.(ViewRoot.java:259)
E/WindowManager( 4255):	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
E/WindowManager( 4255):	at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
E/WindowManager( 4255):	at android.view.Window$LocalWindowManager.addView(Window.java:465)
E/WindowManager( 4255):	at android.app.Dialog.show(Dialog.java:241)
E/WindowManager( 4255):	at android.app.AlertDialog$Builder.show(AlertDialog.java:812)
E/WindowManager( 4255):	at com.phonegap.DroidGap$GapClient.onJsAlert(DroidGap.java:824)
E/WindowManager( 4255):	at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:501)
E/WindowManager( 4255):	at android.os.Handler.dispatchMessage(Handler.java:99)
E/WindowManager( 4255):	at android.os.Looper.loop(Looper.java:130)
E/WindowManager( 4255):	at android.app.ActivityThread.main(ActivityThread.java:3835)
E/WindowManager( 4255):	at java.lang.reflect.Method.invokeNative(Native Method)
E/WindowManager( 4255):	at java.lang.reflect.Method.invoke(Method.java:507)
E/WindowManager( 4255):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
E/WindowManager( 4255):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
E/WindowManager( 4255):	at dalvik.system.NativeStart.main(Native Method)
```

This happens when people are using an Alert in a callback, in this case the reachability API. I'm going to investigate this further, but its the reason there's the infamous "The connection to the server was unsuccessful" is happening.

Of course, once you kill it and restart the app, the problem goes away, but this doesn't provide a great user experience. I'll assign this to myself.