Right, I was dealing with sources, where accidentally all Graphics objects were manually created from BufferedImage objects ;) So I wasn't thinking about the more common case of paint().
22.02.2011, 21:19, "Phil Race" <philip.r...@oracle.com>: > Aside from the fact that its weird, if not downright wrong > to think of a Graphics instance as "closeable", > Graphics instances are not used in the same way as all > the stream type resources for which AutoCloseable is intended. > In most cases they are provided to you in a call to paint() > Releasing a Graphics via explicit call to dispose() only > should be used in the relatively rare use case where you obtained it > yourself to draw on an image or some other surface. > And even then dispose() is not a requirement since the system does > dispose of > the graphics for you in a prompt way that does not require finalisation. > The docs on java.awt.Graphics are extremely dated in that respect. > > -Phil-of-the-graphics-team. > > On 2/22/2011 12:00 PM, assembling signals wrote: > >> Hello, community! >> >> Is java.awt.Graphics not a candidate for AutoCloseable? >> >> In most cases, a Graphics object has to be dispose()'d at the end. >> Couldn't it be extended with close() which would be a delegate to dispose()? >> >> Best regards, >> Ivan G Shevchenko