Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:13:25+00:00 2026-06-13T07:13:25+00:00

I am currently busy writting a javascript library. In that library I want to

  • 0

I am currently busy writting a javascript library. In that library I want to provide some logging about what is going to 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 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, …).

log(severity.information, 'DB opened', db);

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:13:26+00:00Added an answer on June 13, 2026 at 7:13 am

    It’s understandable that objects passed to console.log aren’t GC’ed because you need to be able to inspect them in developer tools after your code has run. I wouldn’t call this a problem at all because that’s how it needs to be when you are debugging your application but the production code shouldn’t do any console logging.

    If you still need to log stuff (or send it somewhere) in production, I would suggest stringifying your object:

    console.log(JSON.stringify(db, null, '\t'));  // '\t' to pretty print
    

    The additional bonus here is that you really capture the object’s state at the time of logging (while logging an object reference doesn’t guarantee that 1).

    Since you are trying to log large objects, be aware that doing this will probably decrease performance, so think twice if you want to do it in production.

    1 – seems to have been fixed in latest Chrome

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently busy creating a search function that queries a user input string
I currently have code similar to this for a form: $('#some-form') .submit(function() { //
I'm busy writing an hangman application and I'm currently checking if some of the
I have a busy photo website that is currently making a new page request
I have an animated .gif that I want to use as a busy indicator.
At school we are busy making a Spotify application. I am currently making an
Currently, I am writing a MiddleWare application that synchronizes information between and accounting application
Currently working with converting SQLException error messages into messages that are more useful for
I'm currently busy working on an IP ban tool for the early versions of
I have a pagination that needs to look like that: a busy cat http://img338.imageshack.us/img338/3180/pagination.jpg

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.