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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:46:02+00:00 2026-05-25T02:46:02+00:00

My problem is basically as follows. There is an instance of a class extending

  • 0

My problem is basically as follows. There is an instance of a class extending EventDispatcher. Everything goes well when I add event listener to the object like this:

myObject.addEventListener('eventName', someFunction, false, 0, false);

But something changes when event listener is added by a weak reference:

myObject.addEventListener('eventName', someFunction, false, 0, true);

Now someFunction is not called even though the line containing dispatchEvent(‘eventName’) is being executed just like before (and there is an external reference to myObject as well).

The application I’m developing is quite complex so, unfortunately, I can’t post the exact code.

  • 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-25T02:46:02+00:00Added an answer on May 25, 2026 at 2:46 am

    You are misunderstaning how GC works, I think. Using a weak reference will not pin down myObject. It could (possibly, not necessarily) prevent the scope in which the handler is declared to be collected (as long as myObject itself is alive). Hence, the callback itself could be collected, causing it not to be executed. It seems this is the case here, according to your description.

    So your goal is to avoid that the scope declaring someFunction is collected. One way could be actually using a hard ref (if you ask me, weak refs are a bad idea, anyway). There may be others, but I don’t know how your app is structured, so I can’t say much.

    Edit to address a comment.

    GC wise, event handling is not different from the general case. When you add a listener, you’re passing a reference to the dispatcher (the reference is the scope that in which the listener is declared). The dispatches stores this reference so it can execute the callback when neccesary. It’s really not that different from this:

    myObject.keepThisReference = someFunction;
    

    Now, myObejct has a reference to someFunction. So, as long as myObject is alive, someFunction will be alive too (unless you set someFunction as a weak ref).

    So, to answer the question in your comment (an object is not referenced anywhere else but has an event listener attached), given this scenario:

    myObject.addEventListener('someEvent',someFunction);
    

    If myObject doesn’t have any other reference and goes out of scope, it is collectable.

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

Sidebar

Related Questions

I am creating a little testing component and am running into a problem Basically
The problem is basically this, in python's gobject and gtk bindings. Assume we have
Basically my problem stems from a desire to have the textbox portion be white,
Basically my problem is with the page at http://wiki.diablocommunity.com/index.php?title=Tristram_Cathedral Please see the screen shots
Basically my problem is that i've adapted a piece of code found here http://social.msdn.microsoft.com/Forums/en-US/vemapcontroldev/thread/62e70670-f306-4bb7-8684-549979af91c1
So basically here's my problem. I'm looking for a solution to allow us to
This is basically a math problem, but very programing related: if I have 1
I have basically the same problem outlined in this question, however I am using
Basically, here's my problem. I'm calling someone else's FORTRAN functions from my C++ code,
Basically like using the out keyword. But the problem is with the out keyword,

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.