[TIMOB-14073] Memory leak in Ti.Buffer
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | n/a |
| Status | Open |
| Resolution | Unresolved |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | n/a |
| Labels | buffer, heap, ios, memory, simulator |
| Reporter | Carter Lathrop |
| Assignee | Unknown |
| Created | 2013-05-21T11:45:06.000+0000 |
| Updated | 2018-02-28T20:03:15.000+0000 |
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.
var buffer = Ti.createBuffer({length: 1000});
var pos = 0;
var id = setInterval(OnInterval, 1000);
function OnInterval() {
buffer[pos++] = 1;
}
Every time OnInterval is called there is a memory loss of 176 bytes.
To rule out loss from the interval mechanism I did a test with a button instead:
var buffer = Ti.createBuffer({length: 1000});
var pos = 0;
var win = Ti.UI.createWindow();
var button = Ti.UI.createButton({ title: 'Click me'});
button.addEventListener("click", OnClick);
win.add(button);
win.open();
function OnClick() {
buffer[pos++] = 1;
}
In that case the heap growth was 164 bytes.
Attachments
| File | Date | Size |
|---|---|---|
| Screen Shot 2013-05-21 at 13.33.03.png | 2013-05-21T11:45:06.000+0000 | 220531 |
| Screen Shot 2013-05-21 at 13.43.39.png | 2013-05-21T11:45:06.000+0000 | 58920 |
I'm having a very similar issue with an apparent memory leak using Ti.Buffer. I'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:
I'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. I can't seem to post a screenshot, but I'm seeing hundreds of records like this in instruments:var stream = file.open( Ti.Filesystem.MODE_READ ); var size = 1024 * 256; var buffer = Ti.createBuffer({length: size}); for (i = 0; i < 10; i++) { bytes_read = stream.read( buffer, 0, size ); if (i < 9) buffer.clear(); } var blob = buffer.toBlob(); stream.close(); buffer.clear();