Reputation: 566
I am working on a piece of code that has a substancial memory leak, I am posting an example function but my entire 11,000 line code has similar functions repeated all over. I am experiencing an average of 5Mb memory leak when I click the Refresh Button. The logic behind the refresh button is to call the empty function of the object. I have researched all over for cyclic references and closures but I am not really sure if the way I set everything to an empty array is correct or should I set everything to null ? Any help would be great. I have to use IE as the app is on IE. Sadly no chrome tools for me :(
/**
* Represents the tasks for the currently loaded patients.
*/
var foo = {
loaded: false,
overdueTaskCounts: [],
unscheduledTaskCounts: [],
currentTaskCounts: [],
scheduled: null,
patientTasks: {},
tasks: {},
taskNumber: 0,
/**
* Unpacks the JSON received from the CareCompass service for the CareCompass task counts.
* @param reply - The JSON representing the data returned from the CareCompass service.
*/
unpack: function unpackTasks(reply) {
var taskCounts = reply.data; * * //This function populates the variables declared above**//
this.scheduled = taskCounts.scheduled;
},
/**
* Removes all the task information related to the loaded patients.
* @param none
*/
empty: function emptyTasks() {
this.loaded = false;
this.overdueTaskCounts = [];
this.unscheduledTaskCounts = [];
this.currentTaskCounts = [];
this.scheduled = null;
this.patientTasks = {};
}
}
Upvotes: 2
Views: 225
Reputation: 42277
This video from Google I/O will show you how memory leaks happen and how to debug your app. http://www.youtube.com/watch?v=x9Jlu_h_Lyw
Grab some coffee and get ready for a great video.
Upvotes: 3