Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1339] Android memory leak

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2014-07-09T22:19:01.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, httpclient, leak, memory
ReporterElie Khoury
AssigneeMauro Parra-Miranda
Created2014-06-12T20:55:46.000+0000
Updated2016-03-08T07:37:44.000+0000

Description

I noticed lots of HttpClientProxy leaks in our Android application. We double checked our code, ran some tests, profiled the same code base on iOS (it was fine on iOS). Eventually we realized the the HTTPClient object is leaking only when there are concurrent xhr requests. Test 1 (Leaks) ------------------ I built a test case and profiled it to confirm our conclusion. In test one, the app will send 20 concurrent HTTP requests. When profiled, it will show that all the HTTPClientProxy objects were leaked, even after invoking GC multiple times. "20 instances of "ti.modules.titanium.network.HTTPClientProxy", loaded by "dalvik.system.PathClassLoader @ 0xb1083270" occupy 5,327,960 (28.38%) bytes." Test 2 (Doesn't Leak) ---------------------------- While with test 2, the requests are queued and sent one at a time (100ms delay between every response and next request). The profile result showed that none of the HTTPClientProxy objects were leaked. I read numerous posts on this forum and most of them were old (from 1.8 days). I'm running my tests on version 3.2.3. Android 4.3.2. Test code below: function xhrRequest(callback) { var xhr = Ti.Network.createHTTPClient({ timeout : 5000, cache : false, onload : function(e) { if (callback) { callback(); } } }); xhr.open('POST', 'https://www.yahoo.com/'); xhr.send(); } function xhrRequestTest1(tests, callback) { var completed = 0; for (var i=0;i

Comments

  1. Mauro Parra-Miranda 2014-06-30

    Hello Elie! I did some testing with your testcase. It doesn't prove the memory leak yet. We need a testcase that: - Does one operation (like your xhr element) - Then we repeat the operation - We can check in the heap that it's growing every time you do that operation - Then you simulate a Garbage Collector call in Android Monitor - And continue doing this operation until it shows that the memory is leaking no matter what you do (by example, running the Garbage collector, as the Android OS would do). As a result of my testing, it claims that Bitmap element is leaking more memory (using MAT). MAT will provide a clue if something is leaking, but it's not a proof yet. If you find a testcase like the mentioned, we can move this to Platform. Thanks a lot!
  2. Mauro Parra-Miranda 2014-07-09

    Customer hasn't replied to us yet.

JSON Source