Titanium JIRA Archive
Alloy (ALOY)

[ALOY-915] Alloy Collection (RESTful) is not releasing memory properly

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionWon't Fix
Resolution Date2014-01-03T17:17:55.000+0000
Affected Version/sAlloy 1.3.0
Fix Version/sn/a
ComponentsRuntime
LabelssupportTeam
ReporterEduardo Gomez
AssigneeTony Lukasavage
Created2014-01-03T16:45:59.000+0000
Updated2014-06-22T13:23:20.000+0000

Description

Issue description

Alloy Collection is not releasing memory properly if fetch is run WITH a callback.

Steps to reproduce

Ti project files here: https://www.dropbox.com/sh/f4h0fkyp08numrm/W9rvtLZ1Rr - To run the app WITH a memory leak: 1) In the ledgerlists.fetch({.... ; lines 15-18 of test1.js ; UNCOMMENT these lines and build the app. To be clear, the lines to un-comment are: {quote} success: function(collection, response){ console.log("fetch finished"); console.log(response); } {quote} 2) Run Instruments {quote} select "Allocations" icon, click "Choose" pick the drop down box "Choose Target" select "Attach to Process" -> scroll down to the "System" heading area, then underneath that, find the app (leakTest1) click on Record (top left); enter uid/pwd if needed on mac osx in the top right corner of Instruments window, put "TiUI" to the filter box now go back to the Ti app that is open/running open up the modal window by clicking on the "TEST1" button close the modal window (then take a look at Instruments) open up the modal window again, then look at Instruments repeat 11 & 12 a number of times (5 or 6) you should see the number of retained objects for the listview increasing. they never get released. {quote} - To run the app WITHOUT a memory leak: 1) In the ledgerlists.fetch({.... ; lines 15-18 of test1.js ; COMMENT OUT these lines and build the app. To be clear, the lines to COMMENT OUT are: {quote} success: function(collection, response){ console.log("fetch finished"); console.log(response); } {quote} **RE-SAVE & CLEAN BUILD OF Ti PROJECT Repeat the above steps 2.->13. to watch Instruments You should not see any memory leak. All the objects are eventually released.

Thoughts

We tried out to unbind the Collection using reset method after the Controller Window closed: E.I. http://stackoverflow.com/questions/9202599/how-do-i-unbind-a-backbone-collection-fetch-callback Since "Using reset with no arguments is useful as a way to empty the collection." http://docs.appcelerator.com/backbone/0.9.2/#Collection-reset We are seeing the Ti objects getting released after the 3rd or 4th time (Under #transient column) Screen shoot: AlloyMemoryLeak_Instruments.jpg Quoted the code lines that were added on our side for testing purposes (controllers/test1.js): {quote} $.closeButton.addEventListener('click', function(e) { $.win1.close(); $.win1.removeAllChildren(); $.destroy(); ledgerlists.reset(); }); {quote} We also attempted to use the Alloy.Collections.instance method with the name of the model file minus the extension as the only parameter to create or access the singleton. However this ended up just getting released the TiWindow Screen shoot: AlloyCollection_SingletonInstance.jpg For example (controllers/test1.js): {quote} // some restful endpoint - testing purposes only //var ledgerlists = Alloy.createCollection('ledgerlist'); var ledgerlists = Alloy.Collections.instance('ledgerlist'); {quote}

Attachments

FileDateSize
AlloyCollection_FetchMethod.jpg2014-01-03T16:58:55.000+0000321048
AlloyCollection_SingletonInstance.jpg2014-01-03T16:45:59.000+0000332387
AlloyMemoryLeak_Instruments.jpg2014-01-03T16:45:59.000+0000312267
leakTest1.zip2014-01-03T17:00:53.000+00009461788

Comments

  1. Tony Lukasavage 2014-01-03

    Project link is a 404. Also, you mention REST, is this using a 3rd party REST adapter? If so, you'll likely get more help reporting the issue to the author of the adapter since we don't support those as part of the Alloy project.
  2. Eduardo Gomez 2014-01-03

    Forgot to attach a screen shoot (AlloyCollection_FetchMethod.jpg) where there is no memory leak (no callback defined)
  3. Tony Lukasavage 2014-01-03

    This issue, based on what I've been given here, appears specific to the restapi.js adapter, which is a 3rd party sync adapter created by Mads Moller here: https://github.com/viezel/napp.alloy.adapter.restapi . It is outside the scope of the ALOY project. You should contact Mads by either logging an issue on the project or messaging him directly to test this and get it resolved. He is generally pretty responsive, but you can contact me if you have a hard time getting help.
  4. Angus Johnston 2014-01-09

    thanks Tony / Eduardo, ive left a message just now on the github repo for Mads.
  5. Javen Wang 2014-03-30

    Hi guys, I've created a PR for this issue: https://github.com/viezel/napp.alloy.adapter.restapi/pull/33

JSON Source