Does the dispose() call potentially flush some drawing operations?
Is it simply not needed if you don't "write" to the graphics context?
Jim would probably be a better person to answer this question, but
since JDK 1.4 or so, Graphics.dispose() doesn't really do anything
heavyweight; we have other internal mechanisms for ensuring that
associated resources are disposed properly. It doesn't (currently)
flush pending operations or anything like that, and nowadays it
doesn't really matter whether you call it or not (it won't leak if
you don't). That said...
dispose is used to free internal resources associated with the contexts
manually. As its documentation states, the finalizer will take care of
those resources anyway, but more aggressive disposing will keep the
resource usage minimal. Graphics, like most objects that might
potentially include native data that needs to be disposed, protects
itself with a finalizer to free the resources even if you forget to
manually dispose it. Thus, dispose() is simply a more aggressive
technique to keep overall resource usage down when you know that you are
done with an object.
So, from the two pieces of code, the one inside your paint routine which
is probably going to be called a lot is probably the one to worry about
disposing more than one you incidentally create during initialization,
though ideally you would dispose both. It's just much more critical in
code that might expect to be called hundreds of times per second (during
a flurry of updates for instance).
On a side note, in 1.4 we removed the need to dispose our regular
graphics objects by moving all of their data into Java structures which
can be garbage collected normally without any need for a finalizer. I'm
not entirely sure about the Graphics objects used in printing, though,
but all of the ones on the screen and on offscreen, volatile, and
buffered images are all "finalizer free". You shouldn't make a habit of
relying on that, though, as I have no idea if any of the ports that
other vendors make might not need have finalizable state in their
graphics and so the dispose() method for them may have non-trivial
meaning...
...jim
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".