I'm currently busy writing a javascript library. In this library I want to provide some information about what is happening with the console.
function log () { if ((window && typeof (window.console) === "undefined") || !enableLogging) { return false; } function currentTime() { var time = new Date(); return time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds() + '.' + time.getMilliseconds(); } var args = []; args.push(currentTime()); for (var i = 1; i < arguments.length; i++) { args.push(arguments[i]); } switch (arguments[0]) { case severity.exception: if (window.console.exception) { window.console.exception.apply(console, args); } else { window.console.error.apply(console, args); } break; case severity.error: window.console.error.apply(console, args); break; case severity.warning: window.console.warning.apply(console, args); break; case severity.information: window.console.log.apply(console, args); break; default: window.console.log.apply(console, args); } return true; }
The above code presents the log function. When called, I provide at least a sequence, a message, and optionally some objects (can be DOM objects such as IDBTransaction, IDBDatabase, ...).
log(severity.information, 'DB opened', db);
Now the problem is that this leads to a memory leak. The problem is that the objects I pass remain in memory using the console.log method. Is there any way to avoid this or clear it?
javascript memory-leaks
Kristof degrave
source share