Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to dispose the graphic context returned from Component.getGraphics()?

Tags:

java

awt

I have learned that you need to call dispose() on Graphics objects that you have created when you are done using them. However, I'm having a hard time figuring out from the API documentation when Graphics objects are created.

Obviously when a Graphics object is passed into a callback, then I haven't created it, and shouldn't dispose of it (or modify it in any other way from what I've heard), and if I call Graphics.create(), then I am creating it and I should dispose of it.

But what about when I call Component.getGraphics()? Is this creating a new Graphics2D object that I am responsible for disposing, or is it returning a reference to an existing object that I shouldn't modify? The documentation doesn't say either way.

like image 954
pavon Avatar asked Nov 14 '22 18:11

pavon


1 Answers

You only dispose Graphics objects that you explicitly create. So in your example you would not be calling dispose on the object you get back from Component.getGraphics(), unless its documentation explicitly states that the object was created for you.

like image 92
Perception Avatar answered Dec 17 '22 15:12

Perception