[TIMOB-19903] Android: Fix crash due to GC of UI native proxies in hyperloop
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2015-11-24T20:22:46.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 5.4.0 |
Components | Android, Hyperloop |
Labels | n/a |
Reporter | Christopher Williams |
Assignee | Christopher Williams |
Created | 2015-11-10T14:49:39.000+0000 |
Updated | 2016-07-28T22:20:56.000+0000 |
Description
If we generate a native UI proxy (say an android.view.View) and add it to a Titanium UI, we see crashes when the UI is GCed. This can bee easily seen in the hyperloop-examples repo. Once we go to an example where we generate a native view and add it to the UI from Titanium (like say Animate View example) and then go back to the main listing - causing a GC of the elements in that view, we see a crash of the app.
Finally managed to get a run with a debug build of the SDk so I can get real info:
Ok, so after a lot of looking at this, I finally nailed the crashes to coming from trying to release an ActivityProxy when we close a Window:
Here's what I think is happening: Our native hyperloop UI views are getting passed in a wrapped version of the current activity. We're not fully cleaning up all of our hyperloop proxies when the window closes - we're just getting the one call to release the views of the top-level ViewGroup we've added into our Ti.UI.View hierarchy. That HyperloopView is blissfully unaware of how to handle releasing all the children. We need to implement some system specifically for UI elements where we track children of a View and release the hyperloop proxies that correspond to all of them.
Ok, so it _does_ look like we have some sort of memory leak regarding the view hierarchy, so that needs to be fixed _but_ that's not the cause of the crash. I can reliably reproduce with a simple example that _doesn't_ use hyperloop and only happens when running on main thread:
When you close the second window, it will reliably crash only if run from the UI thread.
https://github.com/appcelerator/titanium_mobile/pull/7448
Verified the fix. Verified using the hyperloop sample app & the code above & running on main thread. No crash seen. Closing. Environment: Appc Studio : 4.7.0.201607111053 Ti SDK : 5.4.0.v20160727143921 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.5 Appc NPM : 4.2.8-1 Appc CLI : 5.4.0-34 Node: 4.4.4 Nexus 5X - Android 6.0.1