Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26623] iOS: APSHTTP resources are not freed correctly.

GitHub Issuen/a
TypeBug
Priorityn/a
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
Componentsn/a
Labelsn/a
ReporterChristopher Kimber
AssigneeEric Merriman
Created2018-11-21T21:47:43.000+0000
Updated2018-11-30T23:56:27.000+0000

Description

I've noticed that the resources attached to a network request are not freed correctly. I took the demo ‘ti create’ app.js and extended it to make a web request based on the example found at: https://wiki.appcelerator.org/display/guides2/HTTPClient+and+the+Request+Lifecycle You can see after 15mins the memory is still associated with these requests, which should have given GC plenty of time to collect. (instruments.png) If we look at the memory graph associated with these objects we can see that the reference at first is held by both the JS stack via TINetworkNettpClientProxy and the NSURLSession (memorygraph1.png) After a while the GC runs and the JS side of things is correctly freed up just leaving an instance linked to the NSURLSession. (memorygraph2.png) and from then on never gets freed. From Apples docs: {quote}If you no longer need a session, you can invalidate it by calling either invalidateAndCancel() (to cancel outstanding tasks) or finishTasksAndInvalidate() (to allow outstanding tasks to finish before invalidating the object). If you don’t invalidate the session, it automatically goes away when your app is terminated (unless it’s a background session with active tasks). After invalidating the session, when all outstanding tasks have been canceled or have finished, the session calls the delegate’s urlSession(_:didBecomeInvalidWithError:) method. When that delegate method returns, the session disposes of its strong reference to the delegate.{quote} https://developer.apple.com/documentation/foundation/urlsession Looking through the source for APSHTTPRequest I think I can see 2 issues: * The NSURLSession that is created is never “finished” allowing for a memory leak * The NSURLSession delegate method “didBecomeInvalidWithError” is treated as purely an error state, but instead should be considered as a success unless the error object is present

Attachments

FileDateSize
app.js2018-11-21T21:46:27.000+00001518
instruments.png2018-11-21T21:46:28.000+0000123902
memorygraph1.png2018-11-21T21:46:35.000+000096382
memorygraph2.png2018-11-21T21:46:36.000+000059037
tiapp.xml2018-11-21T21:46:47.000+00001959

Comments

No comments

JSON Source