Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-swt-dev] usage finalize() as last resort of resourcemanagement


While it is possible that we could revisit this issue sometime in the future, there is no time (or mandate) to do this right now.



"Ivan Markov" <ivan.markov@xxxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

11/08/2006 03:43 AM

Please respond to
"Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>

To
"Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>
cc
Subject
Re: [platform-swt-dev] usage finalize() as last resort of        resourcemanagement






Your case can be overcome if the GC keeps references to the Font, foreground
color and background color that are set in it (and the rest of the
resources, of course).

I don't say such a scheme is simple to implement, but it is in no way
"impossible".
I tried to do something like this in SWT/Fox, but implemented on the handle
level.

By the way, the current working of SWT also may easily cause segmentation
fault. Consider:
GC gc = ...
Font font = ...;
gc.setFont(font);
font.dispose();

gc.drawText("blah");

This blows up on Fox and probably on GTK+ and Motif too.
On Windows this will generate GDI error, and unpredictable display result,
but not GPF.

So tracking resource references will help avoid the upper problem too, and
will move SWT one step towards "secure API", i.e. one that:
- when NOT used carefully still does not result in JVM GPF (99% of the Java
API has such protections, including AWT is like this)
- afterwards, it could be possible to declare SWT "safe" for use from
unsigned applets in that there is no way for the applet code to cause GPF or
in some other way elevate its privileges by memory corruption.

Of course, whether all that is worth the effort is another topic..

-Ivan


----- Original Message -----
From: "Peter Centgraf" <peter@xxxxxxxxxxxx>
To: "Eclipse Platform SWT component developers list."
<platform-swt-dev@xxxxxxxxxxx>
Sent: Tuesday, November 07, 2006 11:37 PM
Subject: Re: [platform-swt-dev] usage finalize() as last resort of
resourcemanagement


> Danail Nachev wrote:
> > The discussion which I
> > try to find is answer to the question: why finalize() isn't used as last
> > resort for freeing system resources as it is used for FileInputStream
> > for example? Am I missing something here?
>
> The last comment on the bug refers to the specific issue in this case,
which
> is explained in the article.  Some things that appear to be garbage on the
> Java side (because there are no Java references to them) will still be in
use
> (because there are OS-level references to them).  This bad sequence could
happen:
>
> 1. Java objects initialize some resources.
> 2. OS sets up references to resources.
> 3. Java objects go out of scope.
> 4. Java objects are finalized.
> 5. OS resources are disposed.
>
> 6. Java call delegates to OS.
> 7. OS tries to use resources.
> 8. Pain and suffering.
>
> Take the example (from the article) of an X-Windows GC and Font.  A GC can
> refer to a Font via OS-level structures.  From the Java side, the Font
appears
> to be garbage, but it's actually still in use.  If the Font is disposed by
a
> finalizer, things will blow up in an ugly way.  Your JVM dies with a
> Segmentation Fault or somesuch platform-specific nonsense.
>
> --
> Peter Centgraf
> _______________________________________________
> platform-swt-dev mailing list
> platform-swt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/platform-swt-dev

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top