PDA

View Full Version : Memory leak



dmazur
8 Feb 2013, 6:34 AM
I have an application written in ExtJS 4.1.1, which uses one store a lot. I get data samples from server and after some validation I add it to the store using its "add" method. I do this periodically and I remove records I don't need from a store as well. I have several tasks set for store updating.
Problem is, my application is eating more and more of RAM over time and it seems that I have found the source of the problem, but I do not know how to handle it. I extracted code from my application that seems to be the cause of the problem:

Ext.define('TestApp.App', {
extend: 'Ext.app.Application'
});


Ext.application({
extend: 'MyApp.app.Application',

store: null,


launch: function() {
var self = this;
self.store = Ext.create('Ext.data.Store', {
fields: ['when', 'data1', 'data2', 'data3', 'data4', 'data5', 'data6', 'data7', 'data8', 'data9'],
proxy: {
type: 'memory'
},
sorters: [{
property: 'when',
direction: 'ASC'
}]
});
self.beginTask();
},

beginTask: function() {
var self = this;
Ext.TaskManager.start({
run: function() {
var jsonRaw = 'very large JSON'; //about 650 samples normally downloaded from server
var json = Ext.JSON.decode(jsonRaw, true);
//
// //self.store.add(json.data.samples);
//
//// var ln = self.store.getCount();
//// for (var j=0; j<ln; j++) {
//// var record = self.store.getAt(j);
//// self.store.remove(self.store.getAt(j));
//// j--;
//// ln--;
//// record.destroy();
//// delete record;
//// }
//
json = null;
jsonRaw = null;
},
interval: 1000
});
}
});



Now as you can see, store part is commented, but memory leak is still present. Did I made some error with my task management?

chamacs
8 Feb 2013, 9:06 AM
Could be your run interval is too small. Overlapping runs of the task may add up over time.

Just a thought.

If I was to implement something similar, I'd approach it with an async process with a callback method called when processing was complete, that would then call the process again. This would eliminate any possible overlap of processing.

dmazur
12 Feb 2013, 10:11 AM
Could be your run interval is too small. Overlapping runs of the task may add up over time.

Just a thought.

If I was to implement something similar, I'd approach it with an async process with a callback method called when processing was complete, that would then call the process again. This would eliminate any possible overlap of processing.

Thank you for your answer. I don't think that this function takes whole second to complete though. I tried changing the time interval to 10 second (just to be sure), but that didn't changed anything.