开发者

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

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 开发者_Go百科modify? The documentation doesn't say either way.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜