Singleton over collections of objects in Java and garbage collector
<p>I'm using a singleton for granting a unique copy of each object in runtime:</p>

<pre><code>Car object1= CarFactory.createCar(id);
</code></pre>

<p>where the createCar method is:</p>

<pre><code>private static ArrayList&lt;Car&gt; cars= new ArrayList&lt;Car&gt;();

public static synchronized Car createCar(int id){
   Car result= new Car(id);
   int index= cars.indexOf(result);
   if (index==-1){
      cars.add(result);
      return result;
   } else {
      return cars.get(index);
   }
}
</code></pre>

<p>The problem is that with this method each Car have always an reference due to the "cars" collection and the object's memory is never released. How can I improve it?</p>
