static private ArrayList seriesColors = new ArrayList();
public Audiogram(int widthParm, int heightParm)
throws Exception
{
sup
why would you make two post's for the same question? As for your question in general static member variables can cause memory leaks if not handled properly. With properly i mean that those variables live as long as the app lives and you have to take care that for instance an arraylist deletes items which are no longer needed.
Static variables are shared between all the instances of a class. (An instance is created using the "new" operator.)
In these examples; it's probably not a good idea to use a static (instance variable) to store colours in, as the instances will interfere with each other. That variable should be changed to an "ordinary" instance variable.
The final static colorModel in the second example is perfectly fine; It's an immutable object (at least the interface is immutable) and the methods are most likly threadsafe and can be used by a lot of instances at the same time.
Note that the first problem is not a "memory leak". You might say that hte instances unintentionally is leaking data between them, but's its not a classic memory leak where active objects are unintenonally keeping references to "dead" objects.
IF seriesColors for some reason should contain a color for each instance created. (Which is probably a stupid design) the access to the arraylist mustbe syncronized in some way. But I think that is out of scope here...
A collection utilising weak references is generally the solution to the kind of problem in your first example.
See: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/ref/WeakReference.html
With regards to your first question, it's hard to say whether seriesColors would create a substantial memory issue without knowing more about how the rest of the program works. E.g., Are objects ever removed from seriesColors? How often is a new Audiogram created? How many Audiograms will be created over the runtime life of the program? Etc.