Hi,
There are certain number of resources in SWT, like Font,
Color, Region, etc., which can be "selected" and used in another resource, like
Widget or GC.
For example, Font can be selected in a GC object by calling
GC.setFont().
The question is, what happens when the following
wrong code is executed:
Font font = new Font(...);
GC gc = new GC(widget);
gc.setFont(font);
font.dispose(); // Wrong: this font is still used in the GC
object
fc.drawString(10, 10, "test"); // Wrong, the GC uses a Font
isntance which is already disposed: memory corruption may occur.
As far as I know NT Win32, using invalid HDC/HFONT/HWND etc.
handles will not crash the process.
However, I'm not so certain it is true for SWT/GTK. Does it
use some sort of refcounting to track the shared resources, I haven't noticed
anything like this in the sources..
Using the type of code from above in SWT/Fox will lead to JVM
segfault almost 100%.
The question is, are JVM crashes in situations like the above
acceptable in a SWT port, or I should track the shared resources and handle
nicely efforts to dispose these while they are still in use?
Regards,
Ivan
P.S. Hope this question is not for the newsgroup.
|