title: PhoneGap Memory Management
body: <p>For few months now I have been developing an Android app using <code>PhoneGap 2.8</code> and on the javascript side I have used <code>Backbone</code> and <code>jQuery</code> as my main frameworks. As my application has grown to a reasonable size, I have started to notice a considerable memory consumption. Having read different articles that explain why <code>PhoneGap</code> requires considerable amount of memory even to run, I still believe that I can do some optimization to how i use memory. </p>
  
  <p>In <code>BackBone</code> we have a Router object that maps URI-s to specific functions, which render me something called a <code>View</code> object. Not only I implemented my router functions to create a view and render it, but I also store globally reference to currently being displayed view. So before a new view is created, I tell the old view to make some clean up (That is done recursively since views can contain more "sub" views). Under clean up I currently tell view to undelegate his events (I trust <code>Backbone</code> removes the event listeners). Not much more is done currently. Once new view is rendered, global variable will reference the new view. I trust that javascript GC will release the memory, used by the old view. Alas, I dont things this is happening- the more I navigate around my app, the more memory is being used up. I am aware that there is some memory leaking going on, but I can't figure out what is it, that takes memory. One thing I suspect is that old objects are not being garbage collected properly for some reason. I suspect that once I render new html (DOM) over some container, perhaps old <code>DOM</code> is causing memory leaks, perhaps some event handlers are being unnecessarily stored somewhere.  </p>
  
  <p>What I would like to know, if there is any tools or commands or tips on how can I debug/ trace/ measure where memory is being allocated. Is there a way to access all event listeners and measure them somehow (same for DOM). Any article to smart memory efficient techniques would also be appreciated. Currently only thing that I can thing of to do, is to start recursively deleting all attributes of the objects (in the end objects as well) I am willing to destroy. </p>
  
  <p>Any suggestion is very welcome! 
  Thank you in advance. </p>