我正在处理一段有大量内存泄漏的代码,我正在发布一个示例函数,但我的整个 11,000 行代码都重复了类似的函数。当我单击刷新按钮时,我平均遇到 5Mb 内存泄漏。刷新按钮背后的逻辑是调用对象的空函数。我已经全面研究了循环引用和闭包,但我不确定我将所有内容设置为空数组的方式是否正确,还是应该将所有内容设置为 null ?任何帮助都会很棒。我必须使用 IE,因为应用程序在 IE 上。遗憾的是我没有 chrome 工具:(
/**
* 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 = {};
}
}