mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Empty large collections and remove event listeners before reload
Chrome was showing a memory leak after many auto-reloads. Emptying the the collections and removing the event listeners reduces the severity. Before this change 40 reloads would would grow to about 140MB, now it stays around 50MB. (imported from commit 55fbeff9bdd0363bb95929f2981a2de238ff35d8)
This commit is contained in:
committed by
Steve Howell
parent
fc78a2cc66
commit
f1e110c177
@@ -479,6 +479,10 @@ exports.load_more_messages = function load_more_messages(msg_list) {
|
||||
});
|
||||
};
|
||||
|
||||
exports.clear = function clear() {
|
||||
this.stored_messages = {};
|
||||
};
|
||||
|
||||
$(function () {
|
||||
// get the initial message list
|
||||
function load_more(messages) {
|
||||
|
||||
@@ -101,6 +101,14 @@ $(function () {
|
||||
hashchange.changehash(vars.oldhash);
|
||||
});
|
||||
|
||||
function clear_message_list(msg_list) {
|
||||
if (!msg_list) { return; }
|
||||
msg_list.clear();
|
||||
// Some pending ajax calls may still be processed and they to not expect an
|
||||
// empty msg_list.
|
||||
msg_list._items = [{id: 1}];
|
||||
}
|
||||
|
||||
function do_reload_app(send_after_reload, save_state, message) {
|
||||
// TODO: we should completely disable the UI here
|
||||
if (save_state) {
|
||||
@@ -112,7 +120,29 @@ function do_reload_app(send_after_reload, save_state, message) {
|
||||
}
|
||||
// TODO: We need a better API for showing messages.
|
||||
ui.report_message(message, $("#reloading-application"));
|
||||
blueslip.log('Starting server requested page reload');
|
||||
reload_in_progress = true;
|
||||
try {
|
||||
// Unbind all the jQuery event listeners
|
||||
$('*').off();
|
||||
|
||||
// Free all of the DOM
|
||||
$("html").empty();
|
||||
|
||||
// Now that the DOM is empty our beforeunload callback has been
|
||||
// removed.
|
||||
server_events.cleanup_event_queue();
|
||||
|
||||
// Empty the large collections
|
||||
clear_message_list(all_msg_list);
|
||||
clear_message_list(home_msg_list);
|
||||
clear_message_list(narrowed_msg_list);
|
||||
message_store.clear();
|
||||
|
||||
} catch (ex) {
|
||||
blueslip.error('Failed to cleanup before reloading',
|
||||
undefined, ex.stack);
|
||||
}
|
||||
window.location.reload(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -327,7 +327,7 @@ $(function () {
|
||||
get_events();
|
||||
});
|
||||
|
||||
function cleanup_event_queue() {
|
||||
exports.cleanup_event_queue = function cleanup_event_queue() {
|
||||
// Submit a request to the server to cleanup our event queue
|
||||
if (page_params.event_queue_expired === true) {
|
||||
return;
|
||||
@@ -336,10 +336,10 @@ function cleanup_event_queue() {
|
||||
url: '/json/events',
|
||||
data: {queue_id: page_params.event_queue_id}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("beforeunload", function (event) {
|
||||
cleanup_event_queue();
|
||||
exports.cleanup_event_queue();
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user