Java out of heap space error while calling constructor.newInstance(String) multiple times
<pre><code>String type = “ClassNames”;
MyInterface mi = (MyInterface) constructor.newInstance(type);
</code></pre>

<p>Above code snippet is called multiple times (around 3000 Classes) in my program and this leads to out of heap space error.
Heap size reaches to 1024mb.
Any workaround to keep the heap size low?
Thanks!</p>

<p><strong>The interface</strong></p>

<pre><code>public interface MyInterface { 
    public String[] getRowHeader(); 
    public String[] getHeaderTable();    
    public String[][] getDataForSearch();
    public String getInfoText();
}
</code></pre>

<p><strong>Public Class implementation</strong></p>

<pre><code>public TablePanel() {
    try {
        guiInit();
    } 
    catch (Exception exception) {
        exception.printStackTrace();
    }
}
</code></pre>

<p>This guiInit() does the swing component initialization. </p>

<p>In the same class methods are implemented like this below</p>

<pre><code>public String[][] getDataForSearch()  
{
    return rowNames;
}
</code></pre>
