Hi all,
I've created an application that polls for new information for a variable rate - usually between 2 and 10 seconds (near real-time). A problem that I've incurred is there is a memory leak in my application which brings me to my question: what is the most efficient way to poll for new information? I also want the polling to be variable, that is, when the application loads the polling can be set to any number of seconds. The following are code snippets from my current implementation that consists of a
Ext.data.Connection object invoking the request object periodically using a the Ext.TaskMgr.
Below is code from a class I call SC2.View - the constructor for the class creates a single Ext.data.Connection object. The constructor also creates a "task" object for each "data feed". A data feed is really just a JSON web service that can be accessed as frequently as once per second.
Code:
this.conn = new Ext.data.Connection();
this.feeds[i].pollTask = {
view:this,
pollId:i,
run: function(){
this.view.pollFeed(this.pollId);
},
interval: this.feeds[i].pollingFrequency*1000 //JavaScript uses milliseconds
};
These task objects would be invoked using the Ext.TaskMgr using a method called
Code:
startAllPollTasks : function(feedId){
for(var j in this.feeds){
Ext.TaskMgr.start(this.feeds[j].pollTask);
}
},
the SC2.View.pollFeed method invokes the request method of the SC2.View.conn Ext.data.Connection object
Code:
pollFeed : function(feedId){
var url = this.feeds[feedId].url;
this.conn.request({
url:url,
feedId: feedId,
method:'GET',
scope:this,
callback: this.pollFeedCallback
});
return true;
},
this.feeds[i].pollTask = {
view:this,
pollId:i,
run: function(){
this.view.pollFeed(this.pollId);
},
interval: this.feeds[i].pollingFrequency*1000 //JavaScript uses milliseconds
};
I'm sorry the class I've written is very large, I am just focusing on the components related to the server interaction that are contributing to my memory leak. I can also post a barebones working example if that helps anyone understand the problem. Essentially I'm looking for a more memory efficient solution than using the Ext.TaskMgr and an Ext.data.Connection object to poll one to many JSON web services very frequently.
Thanks for any help, EXT JS is an amazing framework with amazing community based support! 