即使没有处理或存储返回的数据,也会发生这种情况。
这是上下文:
HTML 包含
<table border="0" cellpadding="2" cellspacing="0" class="formPanel" style="width:100%">
<tbody><tr>
<td>
<span style="vertical-align:middle;">
<span>Date:
<input id="datePicker" name="DatePicker" maxlength="10" value="20130128"/>
</span>
<input id="go-btn" style="width:80px;" type="button" value="Go"/>
</span>
</td>
</tr>
</tbody></table>
JavaScript 是
$(function(){
// Extracted the previously anonymous function to reduce memory used to store "compiled code"
function processData(data) {
//process data
}
// Extracted the previously anonymous function to reduce memory used to store "compiled code"
function clickHandler() {
var keys = ['googlechrome','firefox','opera', 'webkit', 'ie'];
for(var i = 0; i < keys.length; i++) {
/* Previously a method call
*/
var date = $("#datePicker").val().replace(/-/g, ''),
// A local URL, That returns a max of 5MB.
url = "/get_usage?date="+date;
url += '&user_agent=' + keys[i];
url += "&min_count=250";
$.getJSON(url, processData);
}
}
$("#go-btn").click(clickHandler);
});
一键接收到的数据实际大小约为 10MB,但是当我检查 Chrome 任务管理器中的内存列时,超过 30MB,一段时间后它收集了大约 4MB 的垃圾(不知道这是否无关)。
我怀疑 jQuery 的 getJSON 方法,因为在删除它并将数组大小增加十倍时,整体内存并没有太大差异。