title: Why is Android's JSONObject retained in memory?
body: <p>I am working on an OutOfMemory exception generated when a really large JSONObject is created but never garbage collected by Android's framework. On each subsequent update the memory leak just gets bigger and bigger till I run out of memory. We have a large data structure that changes over time and on each update we send the whole datastructure to the client and refresh it. I know that is not the best way to do it, but changing the whole infrastructure just for Mobile is going to take some time and convincing to do.</p>
  
  <p>As for the here and now, when an Object goes out of scope in Java, it should be marked as available to be garbage collected. I am using the Eclipse MAT tool to do my memory analysis and according to the tool, each String I parse out of the JSONObject has a link back to the original JSONObject. A fix I have is I created a remove function where I iterate through each of the JSONObjects keys and call JSONObject.remove(key) after I am done parsing, that works like a charm and all memory is collected. However, why do I need to do that? I should not have to do that to an out of scope object. Any ideas?</p>
  
  <p>Thanks in advance!</p>
  
  <p>Jared Sheehan</p>