In normal usage the private paintContext field of the Color object should never be used. The graphics code treats colors specially and simply fills the rectangles with the appropriate color rather than invoking its PaintContext object.
But, if anyone ever calls the createContext() method of a Color object directly then this memory could get consumed and cause problems. There are some conditions which could cause us to actually invoke the createContext method on a Color object - such as using your own custom Composite object - but few developers should encounter this problem. If you see Color.createContext coming up in your applications while using fairly common attributes and settings then I'd be interested in hearing about it. But this is a bug (there is a comment in Color.java indicating that we should be using a WeakReference to cache the context which is true if we plan to continue caching the contexts at all) and should be filed. It should appear in the JDC bug list in a couple of days under the ID: 4787241 ...jim --On Thursday, November 28, 2002 16:35:34 +0100 "Jan Bösenberg (INCORS GmbH)" <[EMAIL PROTECTED]> wrote: > Browsing throught the source of the awt classes I had the idea that it > might be useful to cache colors, or at least instances of > ColorPaintContext, in order to reduce memory consumption. Colors are > immutable, therefore there should be no problem with concurrent usage of > objects. > Currently each color is holding an instance of ColorPaintContext, which > again is holding a WritableRaster that is used as a tile during painting. > Often several instances of one and the same Color is being used, which > leads to a lot of unnecessary instances of WritableRaster in memory. > Color caching could easily implemented using a WeakHashMap. > > Has somebody ever tried caching either the colors, the rasters, or the > paint contexts? If yes, did this reduce memory consumption? If no, what > do you think of this idea? ==========================================================================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".