Should I remove listeners?

I don't understand if it is my responsibility to remove every listeners associated to a variable, before I set it to null.
JTable aTable = new JTable( new SomeTableModel() );
aTable = new JTable( new SomeTableModel() );Even if this example isn't very correct, as I should have done setModel on the variable, should I remove the listeners from aTable before the last statement?
In other words, should one put special care before loose a reference to a complex component?
Actually, the setModel method in JTable.java removes the old listeners, suggesting to do the same in my example.
I don't remeber where I read that Sun put a new method into one of the last jdk releases, to obtain the List of listeners.
Thanks
Enrico

Well, yes and no.
It is good practice to remove listeners but it is not nessecary.
The garbage collector in your case will after a unknown time notice that your program are not referencing the JTable at the moment and with that, also the table model and all other components are unreferenced from your program (read thread). Altough the JTable and table model might still reference your program, it should not care.
You might be careful thou if you for instance have an updater-thread running that slowly populates the model. If that thread is not removed, it will be referencing the table, and therefor neither thread, table or tablemodel will be garbage collected.
Regards,
Peter Norell

Similar Messages

  • Adding and removing listeners help please...

    hi guys i have a pop up box that adds a listener depedent on a variable.
    like such
         if(upload_typ != 'O' && upload_typ != 'E')
        {RPanel.DSUB.addEventListener(MouseEvent.CLICK, DatabaseSend)};
       if(upload_typ == 'O')
        {RPanel.DSUB.addEventListener(MouseEvent.CLICK, DataSendOntme)};
        if (upload_typ == 'E')
        {RPanel.DSUB.addEventListener(MouseEvent.CLICK, EncumSendVal)}
    how do i remove the listeners? i continue to see examples of removing listeners but yet i dont see what the remove listener functions should do.
      any help would be greatly appreciated.
    Miguel

    In your case, because you can't be sure what listener was added, you can remove them all, and if they have not been added, no harm:
    RPanel.DSUB.removeEventListener(MouseEvent.CLICK, DatabaseSend);
    RPanel.DSUB.removeEventListener(MouseEvent.CLICK, DataSendOntme);
    RPanel.DSUB.removeEventListener(MouseEvent.CLICK, EncumSendVal);
    Alternatively, you could register the ones that actually get added to an object (associative array) and remove only those when necessary.
    If this post answers your question or helps, please mark it as such. Thanks!
    http://www.chikaradev.com
    Adobe Flex Development and Support Services

  • Itunes won't open, should I remove and reinstall?

    Itunes on windows pc won't open, should I remove and reinstall?  Will I lose my music, etc?

    Microsoft Visual C ++Runtime Library Runtine error E6034
    An application has made an attempt to load the C runtime library incorrectly.  Please contact the application"s support team for more information.
    Many thanks.
    Try the following user tip:
    Troubleshooting issues with iTunes for Windows updates
    Under normal circumstances, an uninstall/reinstall doesn't touch your content. (That being said, it's still always a good idea to maintain a current backup at all times in case of disasters of any sort.)

  • Should I remove Java from  my IMac?

    Should I remove Java from my iMac?  Heard  of security problem with Java and  wondered if I should delete it,

    MadMacs0 wrote:
    I've been going entirely on the almost universal statement that installing Lion does not install Java by default. I'm very aware of the fact that older versions of OS X actually rely on the use of Java for some system functions, but I've been told that is no longer the case. If that were so, then there is no need for any Java to be present, yet you say it is there and you aren't the only one who has told me that.
    But exactly how much Java is installed by default? Obviously not enough to use it for browsing. In the days of the Java 6 Preferences app, it used to alert you that Java was not installed and offer to do so.  What happens with standalone apps like CrashPlan in Lion that require Java, do they have enough, by default, to run?
    The only Java component missing in these OSs is the Java Runtime Environment (JRE). Peruse those installations, looking in these directories, and be enlightened:
    /Applicatons/Utilities/->Java Preferences.app
    /Library/Java/
    /Library/Internet Plug-Ins/->JavaAppletPlugin.plugin
    /System/Library/CoreServices/->
            Jar Launcher.app
            Java Web Start.app
            JavaVersion.plist
    /System/Library/Frameworks->
            JavaFrameEmbedding.framework
            JavaScriptCore.framework
            JavaVM.framework
    /System/Library/LaunchAgents/->
    com.apple.java.InstallOnDemand.plist
    com.apple.java.updateSharing.plist
    /System/Library/Java
    /System/Library/PrivateFrameworks/->
            JavaApplicationLauncher.framework
            JavaLaunching.framework
    to name a few, but probably not all the Java components installed with OS Xs. Then, stop saying Java's not installed, when only the JRE component is missing.
    There has been speculation from some that perhaps it migrated from an older system or that Lion was installed on top of the older system. There's also some confusion these days about what actually constitutes a "clean install".
    AFAICT, it's speculated wrongly. As for the clean install, I define it to occur when the user wipes the drive, installs the OS, sets up everything, and then installs all 3rd-party software. Then, the installation is clean. If there's any migration involved, then it's not clean. i've not done one for over ten years and my OSs started with 9.2->Jaguar->to the current three.

  • Should I remove Java plug-ins?

    I've heard there's a security problem with Java plug-ins.  Should I remove them from my MacBook?  If so how?

    Thanks for the help.
    Winifred

  • If I create an security scope for a group of SCCM-admins should i remove the "Default Scope"?

    Hi,
    If I create an security scope for a group of SCCM-admins  should i remove the "Default Scope”?
    /PS
    /SaiTech

    Yes, it's OK to not add the Default security scope to an administrative user. You can add any custom security scope to an administrative user and it does
    not has to include the Default
    security scope.
    Just keep in mind that you keep at least an administrative user that contains the
    All and/or the Default security scope to not lock yourself out of the console. 
    My Blog: http://www.petervanderwoude.nl/
    Follow me on twitter: pvanderwoude

  • In mapping & symbol should be removed

    Hi Experts,
    I am doing one scenario file to idoc.
    In my file structure i am getting '&' symbol and should be mapped to idoc structure.
    But '&' symbol should be removed and get mapped to target structure.
    In idoc i should not find '&'.
    I have tried with replace string and varialble substitution but it not worked.
    Can you please advise how this can acheive.
    Thank,
    Bhaskar

    Hi Shabharish,
      We have function replace value, with this function can my prob solve?
    or instead of java maping can i go for UDF?
    How can change & symbol to &amp in XML coding?
    Appreciate your inputs
    Thanks,
    Bhaskar

  • Should I remove ini files from my macbook pro or just leave them?

    I regularly move music files from my Windows PC to my MacBook Pro. However I have just realised an ini file which has occurred. Should I remove these files from my MacBook as I don’t want any problems to occur as I use my MacBook Pro for live gigs (to DJ).
    Appreciate your responses.

    Copies them.
    Ciao.

  • Should I remove the blue film on the battery of my brand new Pavilion 15 - n096sa laptop?

    Should I remove the blue film on the battery of my brand new Pavilion 15 - n096sa laptop?

    Hi
    >>I am so sorry about that what happned with your computer 
    >>I would suggest please try doing a system test for F2 fallow the below link 
    Testing for Hardware Failures (Windows 8)
    >>and I belive you have performed recovery using F11 
    >>If still didint work try contacting ebay 
    >>or else call us @ 1800-474 - 6836 and get a set of recovery disc 
    >>try performing recovery using disc 
    Please click "Accept as Solution " if you feel my post solved your issue, it will help others find the solution.
    Click the "Kudos, Thumbs Up" on the bottom right to say "Thanks" for helping!
    I am an HP employee

  • Should i "Remove All Website Data" as well as clear Cookies and Data off my iPad

    Should I "Remove All Website Data" as well as Clear Cookies and data?

    Not for normal everyday use.
    Would you have a specific reason to do so?  If not, don't bother.

  • Had a hard time all of sudden opening photos in PS via Bridge. Updated all my software and now halfway through editing a photo, my actions don't work properly. Should I remove all programs and re-install?

    Had a hard time all of sudden opening photos in PS via Bridge. Updated all my software and now halfway through editing a photo, my actions don't work properly. Should I remove all programs and re-install?

    <moved from Adobe Creative Cloud to Photoshop General Discussion>

  • Should I remove duplicate songs from itunes before connecting new ipad2

    Bought new iPad2.  New to Apple.  Have to connect to iTunes.  Should I remove all duplicate songs from iTunes first, before connecting new iPad 2?

    Download the zip, and run the program you find: http://ottodestruct.com/blog/2006/01/31/easier-to-use-itunes-scripts/
    If you're leery and want more references, do a search for "Quickscripts" and you'll see what people have to say about it!
    Good luck!

  • Should I remove my battery from my macbook Al?

    If I am using my macbook Al "for-days-on-end" connected to a 24"LED Display should I remove the battery or does it not matter?
    I read Li-ion batteries are not affected and have a set lifespan no matter how long or how many times you charge them - but wanted to confirm this info.
    Thanks!

    Leave the battery in. Running it a few hour a week without external power may extend the battery life a bit. If you run without the batter, it won't run at full speed.
    <http://support.apple.com/kb/HT2332>
    "It is strongly recommended that you do not use your MacBook or MacBook Pro while the battery is removed."
    <http://www.gearlog.com/2008/11/applenotebooks_take_hugeperf.php>
    <http://www.tomshardware.com/news/apple-macbook-pro-battery-benchmarks,6643.html >
    <http://blog.wired.com/gadgets/2008/11/new-macbooks-ta.html>

  • Safari and Firefox keep crashing... Should I remove my Flash plug-in ?

    I have only had my iMac since feb. 2008 and I have already had to take my computer back to fix the hard drive after only 1 month of having it.. I thought it was fine until yesterday , I got on my computer and it kept "crashing" on Safari and Firefox.. I was told to check my flash plug-in , but being very new to the mac world I have no idea how to do so.. I am ready to throw my mac out the window or sell it !!! I loved being on it but if I am going to have problems like this I don't want to deal with it..
    Should i remove Quicktime that was on the computer when I bought it ? I am totally lost and any help will be greatly appreciated !!!
    I don't want to "mess" up my computer , people say I can't but after the first problem with it, I am "afraid" to do anything to it...
    Thank you !! Waiting on any help ... Please when answering , give me complete details and instructions on how to go about fixing my computer.....

    Hello faerie:
    Welcome to Apple discussions.
    Since your Mac is still well within warranty, I would take it in to an Apple store and have them fix the problem. There are troubleshooting things that i could suggest, but there is no sense wasting your time hunting for a problem that Apple can shoot much easier (the problem could be either hardware or software).
    Barry

  • Need to replace HD on a Mega 651, which screws should I remove?

    The HD needs replacing , when I take the top of I see the HD, but there are so many screws.
    The Manual doesn't help here. I want to replace the drive with minimum hassle.
    What direction should I work from and what screws should I remove ?
    Any help appreciated !
    Regars, Bornmee

    The multi-lingual manual contains assembly instructions for the Mega 651, it is all detailed in there:
    http://eu.msi.com/index.php?func=downloadfile&dno=2925&type=manual

Maybe you are looking for

  • IPod software update server could not be contacted

    I was attempting to sync my iPod Classic and received a message saying: iTunes cannot read the contents of the iPod.  Go to the Summary tab in iPod preferences and click Restore to restore this iPod to factory settings. I did this and received this m

  • How can i dowload ios 5 to my ipad 2

    how can i download ios 5 to my ipad 2

  • Where is default icons location in oracle form 10g

    hi, Can anybody please tell me, where is the default(given below) icons location in oracle form 10g. I want to user that icons in my form. Image: !c:\icons.gif! thanks mohan

  • HTTP Get Keepalive Wait Time

    Does anyone know how long is the wait time for the built in http get keepalive before it determines there's no answer and marks the service as dying? And is this configurable somewhere? I have an App owner who thinks the load balancer may not be wait

  • Time machine error messages

    I have an external 1 tb backup drive (Seagate) which I've set up for TIME MACHINE.  Although it appears to be working (lights up, able to access back dates), I keep getting a messate "Time maching couldn't complete the backup to "Untitled" (my extere