Sharing and Cloning of Gcs

Internally, each drawable has a gc. All of the drawing primitives that allow an optional gc will use this gc when no gc is specified. By setting a drawable's gc, it is possible to have several drawables share a common gc. Then, by changing this gc, you have changed the drawing behavior (when no gc is specified in the drawing command) of all the drawables that share this gc.

It is important, however, to understand the difference between changing the graphics attributes of a drawable and changing the graphics attributes of a gc. When you change the graphics attributes of a drawable, if any other drawable shares that gc, then the gc is cloned before modifying it. This means that changing the graphics attributes of a drawable cannot change the graphics attributes of any other drawable. However, changing the graphics attributes of a gc will change the graphics attributes of any drawable that uses that gc.

In fact, when you create a drawable but don't specify any graphics attributes, that drawable shares a gc with any other drawables that that haven't specified any graphics attributes. But the first time you specify graphics attributes for that drawable, its gc will be cloned. From then on, unless you explicitly give it a gc, its gc will not be shared, so any changes you make to its graphics attributes will be entirely private to that drawable.