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 6919571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:00:28+00:00 2026-05-27T10:00:28+00:00

If I do something like // global scope function stuff() { // local scope

  • 0

If I do something like

// global scope
function stuff() {
    // local scope
    var a = new SomeHugeMemoryHog();
}

// a doesn't exist down here, but what happened to the memory from the "stuff" scope?

Will I create a memory leak if I don’t set a = null at the end of the stuff scope? Or should I not worry about it? I’m asking this question with emphasis on creating DOM objects (such as a canvas) inside the scope of functions (which I don’t use later at any time). I’m only using the canvas to grab vector dimensions.

  • 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-05-27T10:00:29+00:00Added an answer on May 27, 2026 at 10:00 am

    As others have pointed out that since there is no reference to a outside the function the garbage collector will collect it, most likely on the next collection.

    Some things you need to watch out for, however, is indirect capture. A common place this happens is in event handlers through closure capture. For example,

    function stuff() {
        var a = new SomeLargeObject();
        $("#somediv").click(function () { /* something */ });
    }
    

    Even if the nested function doesn’t use a. a might be kept alive because the activation record of stuff is still alive. Also, DOM objects might be collected differently than normal JavaScript objects which might cause them to be susceptible circular referneces causing collection problems. This most problematic in older browsers and since you reference using a canvas browsers that support canvas tend to be more modern and correctly handle circular references as well as allowing local variables not captured by a closure to collect.

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

Sidebar

Related Questions

Something like var life= { users : { guys : function(){ this.SOMETHING.mameAndDestroy(this.girls); }, girls
is it possible to create something like a global dictionary for pspell? I tried
Something like this might had worked <%= Html.RouteLink(, new { controller = Article, action
I have multiple instances of the following code. var start_time = new Date().getTime(); setTimeout(function
I seem to have an array scope issue. I have a global variable; var
Given: function foo(){ var bar = quux; console.log(/*mystery code here*/); } I'm looking for
I would like to pass a lambda to a funciton. This boost::function<void()> fncPtr(boost::bind<void>([](){/* something
Something like? <fmt:formatDate value=${event.starttime} type=both/>
Something like: for (a,b) in kwargs.iteritems(): if not b : del kwargs[a] This code
Something like this: if self.__class__ == User: logging.debug(%s non_pks were found % (str(len(non_pks))) )

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.