My program was working perfectly until I used a switch statement in JFrame of 2nd class to be opened from 1st class in same package. I got out of memory error.. related to heap space. I removed that switch statement still same error occured. when there is no linkin between jframes they are running perfectly. but when I link them, 1st frame works and on clicking submit button, it dissappears, probably because in its action I've used this.dispose but it isn't opening 2nd frame and after 5-10 minutes I get out of memory error
Class1(JFrame1)
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            qualification = (String)degree.getSelectedItem( );
    contact_num= Integer.parseInt(num.getText());
    String xyz= (String)d.getSelectedItem();
    date=Integer.parseInt(xyz);
    xyz= (String)m.getSelectedItem();
    month=Integer.parseInt(xyz);
    year=Integer.parseInt(y.getText());
    street= (String)(strt.getText());
    name=(String)nme.getText();
    email= (String)e_mail.getText();
    state= (String)stt.getText();
    city= (String)cty.getText();
    gender= (String)sex.getSelectedItem();
    Sample a=new Sample();
    a.setVisible(true);
       this.dispose();
}
Class2(JFrame2)
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    System.out.print("ab");
}                                        
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
    System.out.print("b");
}                                        
Code for Class2 with switch statement due to which I got that error
public Qualification abc=new Qualification();
    Sample aa= new Sample();
    public String s;
    public void open_sample()
    {
        this.setVisible(true);
        switch(abc.qualification)
        {
            case "BE":
            BE1 a=new BE1(); 
            break;
            case "10th/12th":
            C101 b=new C101();
            b.setVisible(true);
            break;
            case "MBA":
            MBA1 c=new MBA1();
            c.setVisible(true);
            break;
            case "CA":
            CA1 x=new CA1();
            x.setVisible(true);
            break;
            default:
        }
    }
private void sa1ActionPerformed(java.awt.event.ActionEvent evt) {                                   s= evt.getActionCommand();
         open_sample();
 }                                   
    private void sa4ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        s= evt.getActionCommand();
   open_sample();}                                   
    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
                      System.out.print("hello");
  }                                        
    private void sa3ActionPerformed(java.awt.event.ActionEvent evt) {                                    
        s= evt.getActionCommand();
       open_sample();
    }                                   
    private void sa2ActionPerformed(java.awt.event.ActionEvent evt) {                                    
           s = evt.getActionCommand();
      open_sample();
    } 
 
     
     
    