0

I am using a java application which opens a scratch file during run time. The scratch file communicates with the arduino board and gives the output. once the communication starts i am unable to use my User interface in java which has a close button instead i tried closing my entire application using end task in task manager. Can you please tell me as how to release the memory associated with the files. I used process. destroy and system.exit(0) but did not work.

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

    if("Disconnect".equals(jButton1.getText()))
    {
        System.exit(0);
    }
    jButton1.setText("Disconnect");

    if(jComboBox2.getSelectedItem()==null)
  {
      System.out.println("Select one port");

  }
 else
  {           Runtime r = Runtime.getRuntime();

    try {
        this.hide();

        //p = r.exec("C:\\Program Files\\Scratch 2\\Scratch 2.exe C:\\Users\\Admin\\Desktop\\fwdbckpwm12.sb2");
        p = Runtime.getRuntime().exec("C:\\Program Files\\Scratch 2\\Scratch 2.exe C:\\Users\\Admin\\Desktop\\scratch files new.sb2");
        //p.destroy();
        //r.exec("C:\\Windows\\notepad.exe C:\\Windows\\ss.txt");
        A4S a4sObj = new A4S(new String[]{jComboBox2.getSelectedItem().toString()});  //defaultline
        //  A4S a4sObj = new A4S(new String[]{"COM16"});  //addedline
        r.gc();
       this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    } catch (IOException ex) {
        Logger.getLogger(serialportselection.class.getName()).log(Level.SEVERE, null, ex);
    } 
finally{
        p.destroy();
        System.gc();

    }

}                                        

}

Sruthi Acg
  • 93
  • 10
  • When the application is closed, the memory associated with is reclaimed by the OS. What does "scratch file communicates with the board" mean? – Kishore Apr 24 '16 at 13:15
  • its a serial communication that takes place between the arduino board and the scratch file – Sruthi Acg Apr 24 '16 at 13:17
  • So you want the file to be deleted when the process is closed? Please post relevant code snippets so that we can understand your question better - http://stackoverflow.com/help/mcve. – Kishore Apr 24 '16 at 13:19
  • no i dont want any file to get deleted. I have a user interface with a button called connect which opens the scratch file during runtime. The serial communication gets started. But when i wanted to close the application i first close my scratch file and den when i try to close my user interface i am not able to do so so i end up closing it by doing end task in task manager. – Sruthi Acg Apr 24 '16 at 13:25
  • Please post the code. – Kishore Apr 24 '16 at 13:28
  • It seems that your code do something like infinite loop in main thread, if so you should use separate thread for processing. – Ilya Apr 24 '16 at 15:10
  • can you pls explain more in detail. – Sruthi Acg Apr 24 '16 at 15:20
  • Your GUI Thread updates the screen and take input, it also call this method. If you block this method the GUI cannot also be updating the screen or taking input. i.e. a thread can only do one thing at a time. – Peter Lawrey Apr 24 '16 at 16:47
  • There is no way your exec() will work. How do you expect it to know the difference between a space in a path and a space between arguments? – Peter Lawrey Apr 24 '16 at 16:50
  • `System.gc()` - this is a big NO, NO. – Kishore Apr 24 '16 at 20:41
  • what do i need to do now to solve this issue – Sruthi Acg Apr 25 '16 at 04:02
  • Once i close the scratch application my control does not come to the user interface or the jform. When i run this file in netbeans build does not automatically stop i forcefully close the run. – Sruthi Acg Apr 25 '16 at 04:14

0 Answers0