Whenever I create any type of GUI component, it normally has one or more event listeners attached to it. I add all of these using addXXXListener() etc. When the component gets garbage collected, does the reference to the event listener get left somewhere, meaning that the event listener object will never get cleaned up until the program finishes? Should removeXXXListener() be used by every GUI component in the finalize() method?
Daniel, No, you don't normally need to worry about eliminating references to the event listeners. Once the component becomes unreachable (i.e., there are no more direct or indirect references to it from any active thread), any objects that it references (e.g., the registered listeners) become unreachable as well. The only thing that might prevent that from occurring is if you've created references to the listeners in some place other than the component's listener list, but there's rarely any reason to do that and is probably not done in your code. ------------------ Brett Spell Author, Professional Java Programming
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop