public static void main(String[] args) throws Exception {
    weka.core.logging.Logger.log(weka.core.logging.Logger.Level.INFO, "Logging started");
    LookAndFeel.setLookAndFeel();
    
    try {
      // uncomment to disable the memory management:
      //m_Memory.setEnabled(false);

      m_Viewer      = new ArffViewer();
      m_Viewer.setExitOnClose(true);
      m_Viewer.setVisible(true);
      m_FilesLoaded = false;
      m_Args        = args;

      Thread memMonitor = new Thread() {
        public void run() {
          while(true) {
            try {
              if ( (m_Args.length > 0) && (!m_FilesLoaded) ) {
                for (int i = 0; i < m_Args.length; i++) {
                  System.out.println("Loading " + (i+1) + "/" 
                      + m_Args.length +  ": '" + m_Args[i] + "'...");
                  m_Viewer.getMainPanel().loadFile(m_Args[i]);
                }
                m_Viewer.getMainPanel().getTabbedPane().setSelectedIndex(0);
                System.out.println("Finished!");
                m_FilesLoaded = true;
              }

              //System.out.println("before sleeping");
              Thread.sleep(4000);
              
              System.gc();
              
              if (m_Memory.isOutOfMemory()) {
                // clean up
                m_Viewer.dispose();
                m_Viewer = null;
                System.gc();

                // stop threads
                m_Memory.stopThreads();

                // display error
                System.err.println("\ndisplayed message:");
                m_Memory.showOutOfMemory();
                System.err.println("\nrestarting...");

                // restart GUI
                System.gc();
                m_Viewer = new ArffViewer();
                m_Viewer.setExitOnClose(true);
                m_Viewer.setVisible(true);
                // Note: no re-loading of datasets, otherwise we could end up
                //       in an endless loop!
              }
            }
            catch(InterruptedException ex) { 
              ex.printStackTrace(); 
            }
          }
        }
      };

      memMonitor.setPriority(Thread.NORM_PRIORITY);
      memMonitor.start();    
    } 
    catch (Exception ex) {
      ex.printStackTrace();
      System.err.println(ex.getMessage());
    }
  }