This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: maximum memory for gcj-compiled executable?


OK, here we go.
I have made this simple program that reads a web page, and then does
nothing with it ;)

Compile it under win32/mingw using Mohan's latest GCC3.3

Run it. 

The heap soon stabilizes and stays put (about 1000KB)

Now open the task manager and watch memory usage slowly grow and grow
and grow....


/Lars Andersen


/*
 * TestThread.java
 *
 * Created on April 3, 2003, 3:16 PM
 */

import java.io.*;
import java.util.*;
import java.net.*;

/**
 *
 * @author  lars
 */
public class TestThread extends Thread
{
    
    
  /** Creates a new instance of TestThread */
  public TestThread() 
  {
  }
  
  public void run()
  {
      while (true)
      {
        long sleep = 3000;
        try
        {
          System.out.println("\n");
          Thread.sleep(sleep);
          performRequest();
          Thread.sleep(200);
          performRequest(); 
          Thread.sleep(200); 
          performRequest();  
 
          long total = Runtime.getRuntime().totalMemory() / 1000;
          long free = Runtime.getRuntime().freeMemory() / 1000;
          System.out.println("Heap Size "+total);
          System.out.println("Free Heap Size "+free);
    
        }
        catch (InterruptedException ex) {} // ignore exception!
      }
      
      
  }
    
  public void performRequest()
  {
    try
    {
      String uri = "/index.html";
      
      java.net.URL url = new java.net.URL("http://www.apache.org"+uri);
      java.net.HttpURLConnection uc = (java.net.HttpURLConnection)
url.openConnection();
      
      uc.setRequestMethod("GET");
      uc.connect();
      
      java.io.InputStream is = uc.getInputStream();
      
      
      String res = read(is);
      
      System.out.println("Length of page="+res.length() );
     
    }
    catch (Exception e) 
    {
      e.printStackTrace(System.out);
    } 
  }
  
  public String read(InputStream is)
  {
    StringBuffer output = new StringBuffer();
    try 
    {
      byte[] buf = new byte[1000];
      int res=0;
      
      res = is.read(buf);
      while(res>0) 
      {
        String s = new String(buf);
        s = s.substring(0,res);
        output.append( s );
        res = is.read(buf);
      }
      is.close();
    }
    catch(IOException exc) 
    {
      exc.printStackTrace(System.out);
    }
    
    return output.toString();
  }
  
  public static void main(String[] args)
  {
    System.out.println("Starting TestThread app");
    
    try
    {
       TestThread tt = new TestThread();
       tt.start();
    }
    catch (Exception e) 
    {
      e.printStackTrace(System.out);
    } 
    
  } 
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]