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?
 
 
Regards
 
Jan

Reply via email to