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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:49:10+00:00 2026-05-17T00:49:10+00:00

I have some troubles with memory leaks in JavaScript. I’m using the Leak Memory

  • 0

I have some troubles with memory leaks in JavaScript.

I’m using the Leak Memory 0.4.5 extension for Firefox which shows me those JavaScript objects which still remain in the memory.

Now I’m not sure how to correctly unbind dom-object from events etc.

For instance, I have a jQuery-widget called ‘dropdownbox’.
In the destroy method I make all the necessary stuff to unbind event-handlers like:

this.box.find('.toggler').unbind();
this.box.remove();
this.box = null;

These 3 lines are a must, or is it possible to call only this.box.remove()?

Till today I never have unbound or cleared something from DOM elements because I thought it doesn’t matter. But I came up with the problem, that after 2 hours of developing on the same site, my Firefox consumes 1GB!

So I read a bit of memory leaks when using closures etc.
So that’s my second question: I use very often closures because they are really cool and handy.
Some people say that you shouldn’t use closures for everything. so for example if we have the following code:

function foo(param1, param2) {
  var local1, local2;
  $('a').click(function() {
    alert('YEAH');
  });
}

It would be better to do it like:

funtion foo(param1, param2) {
      var local1, local2;
      $('a').click(clickEvent);
    }
function() {
  alert('YEAH');
}

Or have I misunderstood that?

  • 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-17T00:49:11+00:00Added an answer on May 17, 2026 at 12:49 am

    You can just call:

    this.box.remove();
    this.box = null;
    

    .remove() will also remove any child elements and their event handlers/data as well. Nulling out the reference held by .box to the element is the last step for complete removal (assuming nothing else it hanging onto it).

    For your other example, the second version is a bit more efficient since the handler’s not copied all over the place, the bigger that handler is the more it makes a difference.

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

Sidebar

Related Questions

I have some troubles with my school project. I have a class: #include Group.h
I have some troubles with plotting the figure. I have a file with some
I have some troubles mapping a JSON Array to RestKit. This is what the
I have some troubles with getting the data from the website. The website source
I have some troubles with a method having a typed List parameter, inherited from
I have some troubles with positioning my label/password field. With this code they both
I have some troubles while writing logs from log4net to the file. I seem
I have some troubles with receiving data on server side. Here goes the code:
Right now I have some troubles. I'm finding a way to solve one problem.
I'm trying to start my java game but I have some troubles with the

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.