This document discusses memory leaks in JavaScript applications and provides best practices to avoid them. It begins by noting that leaks are easy to create unintentionally through timers, closures, and event listeners but difficult to find in long-running apps. It then provides examples of leak patterns to avoid, such as retaining references to DOM nodes or large objects. The document recommends tools for profiling memory usage and traces garbage collection. It concludes by emphasizing that leaks can be critical in long-lived apps and provides tips like naming functions, clearing variables, and using database timeouts.
6. — Concept of reachability
— Blocked event-loop
— Totally optimising
(partions, dynamic intervals)
— New space (1-8Mb)
& Old space (512Mb-1.7Gb)
6
GC
15. 15
var latestNews = function (html) {
var container = document.getElementById("news");
container.innerHTML = html;
container.addEventListener("click", function click() {
showFullItem();
});
var unused = function () {
if (html) console.log("never");
}
}
setInterval(XHR.bind(null, "/get_news", latestNews), 1000);
Deeper down the rabbit hole
18. 18
var latestNews = function (html) {
var container = document.getElementById("news");
container.innerHTML = html;
html = null;
container.addEventListener("click", function click() {
showFullItem(html);
});
}
setInterval(XHR.bind(null, "/get_news", latestNews), 1000);
19. var job = function () {
mysql.query("select * from tasks order by ts desc",
function (err, res) {
use(res);
});
}
setInterval(job, 1000);
19
Long responses
mysql.query({
sql: 'select * from tasks order by ts',
timeout: 1000
});