{ "id": "114698", "key": "TIMOB-14073", "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": "2013-05-21T11:45:06.000+0000", "priority": null, "labels": [ "buffer", "heap", "ios", "memory", "simulator" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-02-28T20:03:15.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 am not sure if I have gotten everything right, but from what I can see there is a memory leak every time I do a write to a Ti.Buffer. \r\n\r\n{code:javascript}\r\nvar buffer = Ti.createBuffer({length: 1000});\r\nvar pos = 0;\r\nvar id = setInterval(OnInterval, 1000);\r\n\r\nfunction OnInterval() {\r\n\tbuffer[pos++] = 1;\t\r\n}\r\n{code}\r\n\r\nEvery time OnInterval is called there is a memory loss of 176 bytes.\r\n\r\nTo rule out loss from the interval mechanism I did a test with a button instead:\r\n\r\n{code:javascript}\r\nvar buffer = Ti.createBuffer({length: 1000});\r\nvar pos = 0;\r\n\r\nvar win = Ti.UI.createWindow();\r\nvar button = Ti.UI.createButton({ title: 'Click me'});\r\nbutton.addEventListener(\"click\", OnClick);\r\nwin.add(button);\r\nwin.open();\r\n\r\nfunction OnClick() {\r\n\tbuffer[pos++] = 1;\r\n}\r\n{code}\r\n\r\nIn that case the heap growth was 164 bytes.", "attachment": [ { "id": "38810", "filename": "Screen Shot 2013-05-21 at 13.33.03.png", "author": { "name": "john_r", "key": "john_r", "displayName": "John Rowtough", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-05-21T11:45:06.000+0000", "size": 220531, "mimeType": "image/png" }, { "id": "38811", "filename": "Screen Shot 2013-05-21 at 13.43.39.png", "author": { "name": "john_r", "key": "john_r", "displayName": "John Rowtough", "active": true, "timeZone": "Europe/Berlin" }, "created": "2013-05-21T11:45:06.000+0000", "size": 58920, "mimeType": "image/png" } ], "flagged": false, "summary": "Memory leak in Ti.Buffer", "creator": { "name": "john_r", "key": "john_r", "displayName": "John Rowtough", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "clathrop", "key": "clathrop", "displayName": "Carter Lathrop", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "iOS Simulator and iPhone (6.0.1)\r\nTitanium SDK 3.1.0 GA", "comment": { "comments": [ { "id": "317693", "author": { "name": "MDChristie", "key": "mdchristie", "displayName": "Malcolm Christie", "active": true, "timeZone": "Europe/London" }, "body": "I'm having a very similar issue with an apparent memory leak using Ti.Buffer.\r\nI'm reading though a filestream to read sections of it to upload in chunks, this is a stripped down sample of what I'm doing:\r\n\r\n{code}\r\nvar stream = file.open( Ti.Filesystem.MODE_READ );\r\n\r\nvar size = 1024 * 256;\r\nvar buffer = Ti.createBuffer({length: size});\r\n\r\nfor (i = 0; i < 10; i++) {\r\n bytes_read = stream.read( buffer, 0, size );\r\n\r\n if (i < 9) buffer.clear();\r\n}\r\nvar blob = buffer.toBlob();\r\n\r\nstream.close();\r\n\r\nbuffer.clear();\r\n{code}\r\n\r\nI've tried various things such as buffer.release() instead of buffer.clear() etc, but the memory footprint grows by about 520KB every time I write to the buffer, and never goes down again.\r\n\r\nI can't seem to post a screenshot, but I'm seeing hundreds of records like this in instruments:\r\n\r\n{code}\r\n#\tAddress\tCategory\tTimestamp\tLive\tSize\tResponsible Library\tResponsible Caller\r\n2\t0x8143000\tMalloc 520.00 KB\t00:21.676.535\t•\t520.00 KB\tFoundation\t_NSMutableDataGrowBytes\r\n3\t0x80c1000\tMalloc 520.00 KB\t00:21.672.005\t•\t520.00 KB\tFoundation\t-[NSConcreteMutableData initWithLength:]\r\n4\t0x7fd7000\tMalloc 520.00 KB\t00:21.055.179\t•\t520.00 KB\tFoundation\t_NSMutableDataGrowBytes\r\n5\t0x7f55000\tMalloc 520.00 KB\t00:21.039.952\t•\t520.00 KB\tFoundation\t-[NSConcreteMutableData initWithLength:]\r\n6\t0x7e7b000\tMalloc 520.00 KB\t00:20.452.586\t•\t520.00 KB\tFoundation\t_NSMutableDataGrowBytes\r\n7\t0x7df9000\tMalloc 520.00 KB\t00:20.448.967\t•\t520.00 KB\tFoundation\t-[NSConcreteMutableData initWithLength:]\r\n8\t0x7d77000\tMalloc 520.00 KB\t00:19.840.489\t•\t520.00 KB\tFoundation\t_NSMutableDataGrowBytes\r\n9\t0x7cf5000\tMalloc 520.00 KB\t00:19.836.874\t•\t520.00 KB\tFoundation\t-[NSConcreteMutableData initWithLength:]\r\n10\t0x7c0b000\tMalloc 520.00 KB\t00:19.239.308\t•\t520.00 KB\tFoundation\t_NSMutableDataGrowBytes\r\n11\t0x7b89000\tMalloc 520.00 KB\t00:19.232.946\t•\t520.00 KB\tFoundation\t-[NSConcreteMutableData initWithLength:]\r\n12\t0x7b07000\tMalloc 520.00 KB\t00:18.628.473\t•\t520.00 KB\tFoundation\t_NSMutableDataGrowBytes\r\n13\t0x7a85000\tMalloc 520.00 KB\t00:18.624.278\t•\t520.00 KB\tFoundation\t-[NSConcreteMutableData initWithLength:]\r\n{code}", "updateAuthor": { "name": "MDChristie", "key": "mdchristie", "displayName": "Malcolm Christie", "active": true, "timeZone": "Europe/London" }, "created": "2014-08-08T10:16:06.000+0000", "updated": "2014-08-08T10:16:06.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }