Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory leak when logging complex objects
    text
    copied!<p>I am currently busy writting a javascript library. In that library I want to provide some logging about what is going to the console. </p> <pre><code>function log () { if ((window &amp;&amp; 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 &lt; 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; } </code></pre> <p>The code above presents my log function. When called I provide at least a sevirity, a message and optionally some objects (can be DOM objects like IDBTransaction, IDBDatabase, ...).</p> <pre><code>log(severity.information, 'DB opened', db); </code></pre> <p>Now the problem I have is that this results in a memory leak. The problem is that the objects that I pass stay in memory by the console.log method. Is there a way to avoid this or clean this up?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload