title: Unable to create PermGen error
body: <p>This is homework, not going to lie. I need to write a program which will generate "java.lang.OutOfMemoryError: PermGen space" error.</p>
  
  <p>Since I wasn't able to attend the lecture, I did hours of research yesterday and this is what I have so far.</p>
  
  <p>At first I created a program and I got constantly this error:</p>
  
  <pre><code>java.lang.OutOfMemoryError: GC overhead limit exceeded
  </code></pre>
  
  <p>Okay, so I did some more research and understood that I didn't get PermGen error because, although that I created objects(String objects) I didn't use them again, so they were considered Garbage. So I changed my code and got constantly this:</p>
  
  <pre><code>Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
  </code></pre>
  
  <p>So this is the code I had at that point:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.List;
  
  public class Test {
  
  public static void main(String[] args) {
      List&lt;String&gt; test = new ArrayList&lt;String&gt;();
      test.add(new String(""));
  
      for (;;) {
          for (int i = 0; i&lt;test.size(); i++){
              test.add(test.get(i));
          }
      }
  }
  }
  </code></pre>
  
  <p>Also under VM arguments I had "-XX:PermSize=2m" (I have tried different values).
  I was told that my code is wrong because it uses the same String over and over. So I tried to change that but I was still unsuccessful. 
  Then I found this code: (<a href="https://stackoverflow.com/questions/3855895/algorithms-that-lead-to-java-lang-outofmemoryerror-permgen-space-error">Algorithms that lead to java.lang.OutOfMemoryError: PermGen space error</a>)</p>
  
  <pre><code>Random rnd = new Random();
  List&lt;String&gt; interned = new ArrayList&lt;String&gt;();
  for (;;) {
      int length = rnd.nextInt(100);
      StringBuilder builder = new StringBuilder();
      String chars = "abcdefghijklmnopqrstuvwxyz";
      for ( int i = 0; i &lt; length; i++ ) {
          builder.append(chars.charAt(rnd.nextInt(chars.length())));
      }
      interned.add(builder.toString().intern());
  }
  </code></pre>
  
  <p>So if I understand correctly this should give me PermGen error? But I still get java heap error.</p>
  
  <p>Also I found this:
  <a href="http://javaeesupportpatterns.blogspot.com/2011/10/java-7-features-permgen-removal.html" rel="nofollow noreferrer">http://javaeesupportpatterns.blogspot.com/2011/10/java-7-features-permgen-removal.html</a>
  Again if I understand correctly, then when using java7 maybe the java heap space error is the one I should be getting? That it's not possible to get PermGen error anymore? Okay, so I've tried to change the compiler and project version to java 6. But still got Java heap space error.</p>
  
  <p>I know it's my fault that I didn't attend the lecture, but I could use some help to understand what am I doing wrong here or what am I missing?</p>