{ "id": "172655", "key": "TIMOB-26623", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2018-11-21T21:47:43.000+0000", "priority": null, "labels": [], "versions": [], "issuelinks": [], "assignee": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2018-11-30T23:56:27.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [], "description": "I've noticed that the resources attached to a network request are not freed correctly.\r\n\r\nI 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\r\n\r\nYou can see after 15mins the memory is still associated with these requests, which should have given GC plenty of time to collect. (instruments.png)\r\n\r\nIf 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)\r\n\r\nAfter 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.\r\n\r\nFrom Apples docs:\r\n{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}\r\nhttps://developer.apple.com/documentation/foundation/urlsession\r\n\r\nLooking through the source for APSHTTPRequest I think I can see 2 issues:\r\n* The NSURLSession that is created is never “finished” allowing for a memory leak\r\n* 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\r\n", "attachment": [ { "id": "65892", "filename": "app.js", "author": { "name": "ckimber", "key": "ckimber", "displayName": "Christopher Kimber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-11-21T21:46:27.000+0000", "size": 1518, "mimeType": "text/javascript" }, { "id": "65896", "filename": "instruments.png", "author": { "name": "ckimber", "key": "ckimber", "displayName": "Christopher Kimber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-11-21T21:46:28.000+0000", "size": 123902, "mimeType": "image/png" }, { "id": "65894", "filename": "memorygraph1.png", "author": { "name": "ckimber", "key": "ckimber", "displayName": "Christopher Kimber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-11-21T21:46:35.000+0000", "size": 96382, "mimeType": "image/png" }, { "id": "65893", "filename": "memorygraph2.png", "author": { "name": "ckimber", "key": "ckimber", "displayName": "Christopher Kimber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-11-21T21:46:36.000+0000", "size": 59037, "mimeType": "image/png" }, { "id": "65895", "filename": "tiapp.xml", "author": { "name": "ckimber", "key": "ckimber", "displayName": "Christopher Kimber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-11-21T21:46:47.000+0000", "size": 1959, "mimeType": "text/xml" } ], "flagged": false, "summary": "iOS: APSHTTP resources are not freed correctly.", "creator": { "name": "ckimber", "key": "ckimber", "displayName": "Christopher Kimber", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "ckimber", "key": "ckimber", "displayName": "Christopher Kimber", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "TI SDK 7.5.0 GA\r\niOS 11.4.1", "comment": { "comments": [], "maxResults": 0, "total": 0, "startAt": 0 } } }