Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26811] iOS: Memory leak in Ti.Network.HTTPClient

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2019-04-25T10:31:22.000+0000
Affected Version/sRelease 7.5.0
Fix Version/sRelease 8.0.1
ComponentsiOS
Labelsn/a
ReporterLuke Lu
AssigneeJan Vennemann
Created2019-01-31T03:34:16.000+0000
Updated2019-04-25T10:31:22.000+0000

Description

Description

After upgrade sdk version from 6.3.0 to 7.4.1/7.5.0, IOS start to have a big memory leak issue when making api requests. The app is going to crash when memory are too high.

How to reproduce

I have create a simple app with only one api request which will be called every 10 seconds, you can build the app from https://github.com/lukeluluke/simpleApp.git 1. Clone the project and build with sdk v7.5.0.GA 2. Use Instruments to monitor the memory usage and leaks 3. You will find the memory keep increasing , and the are memory leaks for almost each api request. 4. Rebuild the app with sdk v.6.3.0.GA. 5. Use Instruments to monitor the memory usage and leaks 6. You will see the is only one leak in the beginning I have attached the screenshots of profiling tool

Update

I have upgraded xcode to latest version, and removed the setInterval function, memory leaks still exist when trigger api calls manually. Please see screenshots below.

Attachments

FileDateSize
v6.3.0.GA.png2019-01-31T03:34:09.000+0000468078
v7.5.0.GA_memory_leak.png2019-01-31T03:34:09.000+0000658861
v7.5.0.GA_xcode_10_production_app.png2019-02-01T00:28:54.000+0000403039
v7.5.0.GA.xcode_10_simpleApp_remove_setInterval.png2019-02-01T00:29:32.000+0000433169
v8.0.0.v20190123061938_memory_leak.png2019-02-07T02:47:31.000+0000667702

Comments

  1. Luke Lu 2019-01-31

    I know this is not the correct project to report, but this is the only project I can select when creating the issue
  2. Rakhi Mitro 2019-01-31

    [~luke_lu], Thanks for reporting this. Can you please try using the upper Xcode version 10/10.1 and let us know the results.
  3. Jan Vennemann 2019-01-31

    [~luke_lu], you are using setInterval to make the request. There is a known leak in 7.5.0.GA related to timers that was fixed in TIMOB-26688. This fix is included in the upcoming 7.5.1.GA release. You can already check it out via ti sdk install -b 7_5_X.
  4. Luke Lu 2019-01-31

    For our production app, it has memory leaks and crash a lot since upgraded sdk from v6.3.0.GA to v7.4.1.GA. When we profiling the memory usage, we found memory will increase for each api request, that is why I use setInterval function to simulate multiple api requests.
  5. Rakhi Mitro 2019-02-03

    [~luke_lu], Did you manage to check using ti sdk install -b 7_5_X?
  6. Luke Lu 2019-02-05

    I have tried 7_5_X and 8_0_X, memory leaks still exist. I have updated the test app's git repository, you can test the newest code. Thanks
  7. Rakhi Mitro 2019-02-06

    Hello, Our engineering team verified the fix on SDK 8.0.0.v20190123061938 in branch 8_0_X. Can you try using the following version and let us know the results. *appc ti sdk install 8.0.0.v20190123061938*.
  8. Luke Lu 2019-02-07

    Hi Rakhi, i have installed 8.0.0.v20190123061938, but it doesn't help. I can still see the memory leaks by using Instruments. Please see attached screenshot. Can you please review the code of sample app (only a fews lines), are there something we need to do after make api calls. Thanks !v8.0.0.v20190123061938_memory_leak.png|thumbnail!
  9. Jan Vennemann 2019-02-07

    [~luke_lu], these look different then those from your previous example. I'll take a look!
  10. Jan Vennemann 2019-02-08

    Alright, after some comparison between 6.3 and 7.X it seems like we indeed leak some memory in our HTTP client. Moving this to TIMOB for further investigation.
  11. Jan Vennemann 2019-02-08

    PR: https://github.com/appcelerator/APSHTTPClient/pull/48
  12. Jan Vennemann 2019-02-18

    PRs to update the APSHTTPClient library in the SDK: PR (master): https://github.com/appcelerator/titanium_mobile/pull/10704 PR (8_0_X): https://github.com/appcelerator/titanium_mobile/pull/10705
  13. Jan Vennemann 2019-03-11

    PR (aps_sdk): https://github.com/appcelerator/aps_sdk/pull/332
  14. Jan Vennemann 2019-03-19

    [~ssekhri], add the following below [this line](https://github.com/lukeluluke/simpleApp/blob/e6c265c2dc0b7073a3da50feabb0ec2f616b4d6b/SimpleProject2/app/controllers/index.js#L22v) to force the HTTP client to get cleared immediately.
        xhr = null;
        
    Otherwise it might take a while until the JS GC kicks in and actually deletes the client and all of its resources (including the leaking objects). You should now no longer see any leaks related to networking.
  15. Jan Vennemann 2019-03-19

    Ok, there still seems to be an issue with leaking objects. I tried with a forced garbage collection and in fact the leaks now only show after a GC. Giving this another pass tomorrow.
  16. Satyam Sekhri 2019-03-25

    FR Passed. Merged to master and 8_0_X
  17. Luke Lu 2019-04-03

  18. Samir Mohammed 2019-04-25

JSON Source