-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
5.0
-
x86
-
windows_xp
A DESCRIPTION OF THE REQUEST :
A product that makes a great deal of use of Color objects has to be written carefully to make sure that memory isn't wasted.
The following all return different objects
Color c1 = Color.white;
Color c2 = Color.decode("-1");
Color c3 = new Color(255, 255, 255);
It should be quite pooible for Color.decode to determine that -1 = white and return that instance.
If the Color class contained a static map of previously created Colors then it could look these up and return an existing instance before attempting to create a new instance of the same value.
This map should be prepoplated with the standard color types, "white", "black", "red" etc...
Color.getByRGB(255, 255, 255) would then return the same as Color.white
Also some arbritary call such as
Color.getByRGB(12, 100, 123);
would always return the same object instance.
JUSTIFICATION :
Save resources and object construction/deletion time.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A single instance of Color for a single color value
ACTUAL -
Multiple instances of Color for a single color value
---------- BEGIN SOURCE ----------
Color c1 = Color.white;
Color c2 = Color.decode("-1");
Color c3 = new Color(255, 255, 255);
assert(c1 == c2);
assert(c1 == c3);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
It is not difficult for a project to create their own factory class to do this. However all team members need to be trained to use that rather than use the standard Color constructors and methods.
###@###.### 2005-05-06 05:50:45 GMT
A product that makes a great deal of use of Color objects has to be written carefully to make sure that memory isn't wasted.
The following all return different objects
Color c1 = Color.white;
Color c2 = Color.decode("-1");
Color c3 = new Color(255, 255, 255);
It should be quite pooible for Color.decode to determine that -1 = white and return that instance.
If the Color class contained a static map of previously created Colors then it could look these up and return an existing instance before attempting to create a new instance of the same value.
This map should be prepoplated with the standard color types, "white", "black", "red" etc...
Color.getByRGB(255, 255, 255) would then return the same as Color.white
Also some arbritary call such as
Color.getByRGB(12, 100, 123);
would always return the same object instance.
JUSTIFICATION :
Save resources and object construction/deletion time.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A single instance of Color for a single color value
ACTUAL -
Multiple instances of Color for a single color value
---------- BEGIN SOURCE ----------
Color c1 = Color.white;
Color c2 = Color.decode("-1");
Color c3 = new Color(255, 255, 255);
assert(c1 == c2);
assert(c1 == c3);
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
It is not difficult for a project to create their own factory class to do this. However all team members need to be trained to use that rather than use the standard Color constructors and methods.
###@###.### 2005-05-06 05:50:45 GMT
- relates to
-
JDK-6293426 Add static methods to Color to convert RGB components into RGB color value
- Closed
-
JDK-5095570 Color object should return a hex via some method like getHex()
- Closed