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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:49:14+00:00 2026-06-06T10:49:14+00:00

QUESTION ONE: In the following example, ive added a listener to the foundMic. My

  • 0

QUESTION ONE:

In the following example, ive added a listener to the foundMic. My question is if i re-run the foobar.initMic(); to reinitialize the microphone will i end up with a dead event listener floating in memory, and would it be picked up by garbage collection? Does calling the .getMicrophone() just reattach the same resource to foundMic or does it destroy the old foundMic and create a new instance of foundMic in memory.

As in if its the exact same foundMic then adding the event listener will silently fail and not create a second listener. But if foundMic becomes a new instance then it would be creating a new listener. Then back to the question about garbage collection, would it be considered unreferenced for clean up?

public class foobar {

    public static var foundMic:Microphone = null;

    public static function initMic():void {
        foundMic = Microphone.getMicrophone();
        foundMic.codec = SoundCodec.SPEEX;
        foundMic.setSilenceLevel(0, 5000);
        foundMic.gain = 50;
        foundMic.setUseEchoSuppression(true);
        foundMic.soundTransform.volume = 1;
        foundMic.addEventListener(StatusEvent.STATUS, onMicStatusEvent);
        return;
     }

    public static function onMicStatusEvent(event:StatusEvent):void {
        if (foundMic && !foundMic.muted) someButton.enabled = true;
        else someButton.enabled = false;
        return;
    }

} // END CLASS

QUESTION TWO:

Based on question one, if i added a remove listener just before adding the listener, does that actually remove the listener on the second time ran which was created when the method was ran the first time? Or is that foundMic already a new instance from the .getMicrophone() so nothing is removed because the first listener is already floating in memory associated with the previous instance of foundMic?

    public static function initMic():void {
        foundMic = Microphone.getMicrophone();
        .
        .
        .
        foundMic.removeEventListener(StatusEvent.STATUS, onMicStatusEvent);
        foundMic.addEventListener(StatusEvent.STATUS, onMicStatusEvent);
        return;
     }
  • 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-06T10:49:16+00:00Added an answer on June 6, 2026 at 10:49 am

    foundMic will just be assigned a new value which is a reference to to the Microphone – nothing should be garbage collected.

    A case where the garbage collector should kick in is something like this:

    var someVar:Sprite;
    for(var i:int = 0; i < 5; i++)
    {
        someVar = new Sprite();
    }
    

    In this case you’ve created 5 new Sprite objects but ended up with only one assigned to the someVar variable – the other 4 should get garbage collected at some point because they are not referenced by any variable.

    As far as question two, the code you have should give you an error the first time you call initMic() since at that point there is no onMicStatusEvent listener yet. Before trying to remove the event listener first test to see if it exists:

    if(foundMic.hasEventListener(StatusEvent.STATUS)
    {
        foundMic.removeEventListener(StatusEvent.STATUS, onMicStatusEvent);
    }
    foundMic.addEventListener(StatusEvent.STATUS, onMicStatusEvent);
    

    This code will always remove the event listener first if it exist and then subsequently add a new event listener. However, in this case I don’t see any reason for this, as addEventListener by itself should work just fine – multiple calls are all on the same object, so no matter how many times you call initMic() you should only have one event listener running – there’s no need to manually remove the listener and then recreate.

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

Sidebar

Related Questions

My question is essentially the same as the following one but the answer did
Based on the following question: Check if one string is a rotation of other
The following question was asked in one of my interview (few years back) What
My question is related to the following two: Emacs - Multiple columns one buffer
I have a question regarding the following code snippet I came across in one
Following a question posted here about how I can increase the speed on one
I had a question answered which raised another one, why following does not work?
I've got the following question. I've got one class Instellingen that's a field in
example if i have follow table company one ( cid = 1 ) following
Question ONE: I'm still pretty new to .net, but have used Visual Studio for

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.