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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:04:49+00:00 2026-06-08T03:04:49+00:00

Having developed various non-trivial applications in Actionscript (which, as a dialect of ECMAScript shares

  • 0

Having developed various non-trivial applications in Actionscript (which, as a dialect of ECMAScript shares a lot with JS) I’m now used to paying extra attention to (obsessing over) event listeners. At some point, after profiling various apps and reading related literature, it became obvious that the Flash player’s garbage collector would have a hard time releasing unused resources when event listeners were present (i.e. added but never removed).

This led to a standard practice of defining (and systematically calling) destructor-like methods for all types that acted as event listeners. The latter were responsible for removing all listeners that were added at initialization-time. As a side effect, this required forgoing the use of unnamed functions as event listeners as all addEventListener(someMethod) calls had to be matched by a ‘symmetrical’ removeEventListener(someMethod). Another alternative would be using weak references.

Now, moving on to Javascript, judging from how integral unnamed functions (and closures) are to the language, their widespread use as event listeners, as well as the general lack of listener-related cleanup code to be found on the internet, it seems that the aforementioned shortcomings of Actionscript’s runtime are not shared by the browser.

Specifically, in the case of plain Javascript and DOM events, I have come to understand that when some part of the document is destroyed, the GC will release all related resources regardless of whether any listeners are attached (something that is not true for AS and its ‘document’, the display-list).

I suppose that the same holds for jQuery which primarily deals with the DOM (factoring in the possibility that jQuery internally performs its own cleanup in some cases).

Is this correct?

And what about dealing with custom events (and their listeners) which don’t originate from the document but are defined and triggered using some library, such as Backbone’s Event module or the Node.js EventEmitter? Should one expect a similar cleanup functionality ‘for free’ or is this clearly a different case where one should take care to remove any added event listeners (from ‘dead’ objects) in order to avoid memory leaks?

(If this feels too generic, I’d be happy to provide concrete examples as a basis for further discussion)

  • 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-08T03:04:50+00:00Added an answer on June 8, 2026 at 3:04 am

    I don’t think there’s anything “for free” in Javascript, and I believe it has the same issues with GC on removed DOM elements.

    This is one of the benefits of using a good library. You mentioned jQuery — it’s pretty diligent about removing listeners when altering the DOM. For instance:
    http://api.jquery.com/remove/

    In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

    So don’t get too happy, but using something diligently like jQuery can keep you relatively safe.

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

Sidebar

Related Questions

I've got the DTD for OFX 1.03 (their latest version despite having developed and
We are having an application developed for BlackBerry - a pretty big one only.
I've developed an android app and it is having an issue while the user
I have developed a WinForm Application with VB.Net (VS2010) having Office 2010 Professional Installed,
I am having an issue with a website developed using ASP.Net/C# sometimes taking all
Having been an imperative developer for some years now, I had never had the
BACKGROUND: I'm self-taught in VB.net, having been a VB6 developer for years. I'm now
When designing tables, I've developed a habit of having one column that is unique
Can anybody tell me, how do i create website which supports various screen resolution
As a Java developer I've become accustomed to having dependency injection available in applications.

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.