SWT and memory management

Oct 20, 2003 19:23 · 152 words · 1 minute read

Pazu laments the pain of SWT. I was seriously considering Eclipse as an application framework, and SWT’s memory management needs were among the reasons that I opted for another path.

For those who haven’t looked at SWT, here’s the scoop: every SWT component (including ones that you write) have a dispose() method. If you make a panel that has several widgets (or even fonts and colors!) on it, you need to keep track of those and explicitly call their dispose() methods from your own dispose() method. If you don’t, you’ve got a memory leak… because SWT will never release the native widgets that it has allocated.

Why does SWT have this bit of nastiness and Swing does not? Because Swing doesn’t allocate native widgets. It draws all of its widgets, directly in Java code, using basic AWT calls.

If Java had real, reliable destructors this would not be a problem. But, alas…