Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1579] Memory leak: XML DOM NodeProxy never releases proxy objects from cache on Android

GitHub Issuen/a
Resolution Date2011-04-17T01:56:34.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.5.0
Labelsandroid, defect, dom, memory, xml
ReporterBrion Vibber
AssigneeDon Thorp


I've been hitting terrible out-of-memory errors while working on our StatusNet Mobile client app on Android. On some investigation, it seems that the XML-related code is leaking a lot of memory:

The caching code in NodeProxy.getProxy() says:

// We cache node proxies so we're not constructing new ones on every single call
// on node finalize we have to go back through and remove each proxy

but I don't see any finalizer on NodeProxy and friends.

Dumping the proxy objects into an ever-growing HashMap means that DOM-related objects never get garbage collected once they've been accessed from JS code: both the proxy and the native object are always referenced from the HashMap.

Simply removing the addition of proxy objects into that proxyCache hash map makes my app's memory usage MUCH more stable. If the cache is necessary, weaker references should probably be used to ensure that the garbage collector can release the proxy objects.


  1. Don Thorp 2011-04-15

    After discussion, we've decided to remove the cache altogether. If the Ti developer wants to cache a node he/she can. iPhone impl doesn't seem to be preserving identity either so this should not be an issue.

  2. Don Thorp 2011-04-15

    (from [8c4255ae53929d6007537ea6d2275444e19e98fa]) [#1579 state:fixed-in-qa] completely removed the Node cache. To test you should be able to process several xml documents and see memory eventually GC. The original implementation had the cache as static so it would grow w/o bound and never clean with each XML document processed. Thanks to Brion Vibber (https://appcelerator.lighthouseapp.com/users/100533">https://appcelerator.lighthouseapp.com/users/100533) for the original find http://github.com/appcelerator/titanium_mobile/commit/8c4255ae53929d6007537ea6d2275444e19e98fa"> http://github.com/appcelerator/titanium_mobile/commit/8c4255ae53929...

  3. Thomas Huelbert 2011-04-15

    loaded a few xml docs, and saw the GC kick in
    freed X objects / X bytes in Xms

    closing as resolved.

JSON Source