Re: [java-gnome-hackers] WeakReferences going away
Brought to you by:
afcowie
From: Philip A. C. <pch...@pc...> - 2003-02-27 18:39:29
|
On Thu, 2003-02-27 at 12:10, Tom Ball wrote: > In this case, I think the problem is related to my style of app > development: I never keep listener references in my app, but instead > just attach them to a widget and forget about them: >=20 > Button cancelButton =3D fontsel.getCancelButton(); > cancelButton.addListener(new ButtonListener() { > public void buttonEvent(ButtonEvent event) { > if (event.isOfType(ButtonEvent.Type.CLICK)) { > fontsel.destroy(); > } > } > }); >=20 Yes, this does seem to be an issue of coding style. Many, many code examples of Swing use inner classes as event handlers. Not to start any flame wars, but I *personally* dislike inner classes and very rarely (if ever) use them. However, my personal preference does not matter. Java allows developers to do this and many swing developers (and some IDEs w/ GUI designers) use this heavily. Therefore, we should code to support *both* methods. (Disclaimer: I realize that the use of inner classes are not the only possible cause of this problem, but would probably be the most likely.) > But there I think good documentation is the best one can do here. Then good documentation it shall be. Even if this weren't a problem, good documenatation is a must. :-) > If memory isn't too big an issue (or if we want to create a "debug" > version of our libraries), we can keep a WeakReference'd static list in > each listener class of the current listeners and what widget they are > listening to. Some key sequence (such as Ctl-Shift-F10) can trigger the > dumping of this list out to the command line for debugging purposes.=20 > This beats poking around in a heap profiler, and is much more likely to > be used by app developers. If you want, I can add this feature soon. I think that this would be a *very* nice feature in a "debug" version. --=20 Philip A. Chapman Application Development: Java, Visual Basic (MCP), VB for Applications, PostgreSQL, MySQL, MSSQL Linux, Windows 9x, Windows NT, Windows 2000, Windows XP |