axemclion / jquery-indexeddb

An IndexedDB Plugin for Jquery.
Other
195 stars 71 forks source link

Memory Leak when use "add" function #14

Closed ctwong11 closed 11 years ago

ctwong11 commented 11 years ago

hi!

I am using the plugin to add a high volume of records into the indexedDB. However, I found a memory leak issue when use the "add" function.

e.g.

for(var i=0;i<10000;i++) { $.indexedDB("ABC").objectStore("DEF").add(item).done(function () { console.log("added item to indexedDB"); }); }

It takes up a chunk of memory and never release back to the system. I ran a chrome heap stack profile snapshot and i saw it created a lot of new objects which did not being deleted after the operation. Did i use the plug in wrongly? Any problem of my syntax?

Best, ct

axemclion commented 11 years ago

I would actually cache the object, so that I reuse the same object store everytime. Infact, I would even use an explicit transaction and object store ... something like this

var o = $.indexedDB("ABC").objectStore("DEF");
for(var i=0;i<10000;i++)
{
o.add(item).done(function () {
console.log("added item to indexedDB");
});
}

Would love to see your data on how the memory seems to increases in both cases ... .are you using a heap profile on Chrome ?

ctwong11 commented 11 years ago

Thanks axemclion.

I ran your code but it doesn't help much. The easiest way to observe the problem is open up windows task manager then bring up the memory usage screen. You could see the memory is consumed during the execution of the for loop. However, it wont release back to system after the completion of the for loop.

best, ct

axemclion commented 11 years ago

Can you also add information about the Browser used, the version and any other details. I was looking at chrome using the chrome profiler.

ctwong11 commented 11 years ago

i am using google chrome version 22.0.1229.79 m

ctwong11 commented 11 years ago

I created a brand new project and a simple indexedDB. Then ran your code:

var o = $.indexedDB("ABC").objectStore("DEF"); for(var i=0;i<10000;i++) { o.add(item).done(function () { console.log("added item to indexedDB"); }); }

By observing at windows task manager, the memory bar went up once the for loop is called. However, it never go down unless you close the chrome browser window.

I then ran a chrome profiler -> heap stack snapshot -> capture before "for loop" profile + capture after "for loop" profile -> click comparsion mode. You can see some new system objects and array is created without deletion.

Best, ct

ctwong11 commented 11 years ago

hi axemclion,

any follow up on this issue?

best, ct

axemclion commented 11 years ago

Looking at it now. Planning to fix this over the week end.

axemclion commented 11 years ago

I am trying to compare this against writing IndexedDB using the native API, not able to see the difference. Can you attach the heap shots so that we can analyze it ?

axemclion commented 11 years ago

Closing issue as no additional data was available to debug, and issue could not be reproduced