Mac OS X 10.5.8, Java 1.5.0_22, NetBeans 6.7.1 Profile Memory every 10 allocations. The first chart shows a nearly linear growth in surviving generations, while the second shows that those thousands of instances take almost no memory.
Mac OS X 10.5.5, Java 1.5.0_16, NetBeans 6.1 Profile Memory every 1 allocation:
<pre><code><span style="color:#000">public class MemoryAllocationTest { public static void main(String[] args) { while (true) { long startTime = System.nanoTime(); byte[] bytes = new byte[1024 * 1024]; System.out.println("Time taken in milliseconds : " + ((double)(System.nanoTime() - startTime) / 1000000)); } }}Time taken in milliseconds : 1.642Time taken in milliseconds : 1.566Time taken in milliseconds : 69.078Time taken in milliseconds : 1.679Time taken in milliseconds : 1.704Time taken in milliseconds : 69.402Time taken in milliseconds : 1.666Time taken in milliseconds : 1.562Time taken in milliseconds : 69.145Time taken in milliseconds : 2.14Time taken in milliseconds : 1.677Time taken in milliseconds : 68.013</span></code></pre>