Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Memory profiler for Java?

Options
  • 24-08-2004 2:30pm
    #1
    Registered Users Posts: 21,264 ✭✭✭✭


    Does one exist? I have an application which is running out of memory in W2K (works fine in XP). Want to see where the memory is being hogged.


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Does it always run out of memory? One thing I've noticed about Java is that the virtual machine is never given a set amout of memory, but rather the amount seems to be set by Windows (or some damned stupid algorithm in the VM).

    Either way, YourKit have a profiler you can get for between €99 and €120, depending on whether you qualify for the academic of personal licence schemes.

    Another thing you can do that worked pretty well for me when I was working on an application that suffered this was to monitor the amount of memory free to the VM, and force a garbage collection when it dropped below a certain percentage.
    private Runtime exec = Runtime.getRuntime();
    private int MIN_MEMORY = 25;
    
    if (exec.freeMemory() <= exec.maxMemory() / 100 * MIN_MEMORY)
    {
       System.out.println("Running garbage collector...");
       System.gc();
    }
    

    Unfortunatly, this isn't foolproof, but might let your app live a little longer... I had manager to get lifespans of 200%+ over the original amount of time.


  • Registered Users Posts: 151 ✭✭Paulmee


    JProfiler should help you.
    http://www.ej-technologies.com/products/jprofiler/overview.html

    Theres a 30 day trial version free.
    I used it quite a bit and its useful, it works with the Eclipse IDE aswell to help development.


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    That code is not really any use as it is impossible to force the garbage collector to run in Java. The only time you can guarantee that the GC will run is just prior to an outOfMemoryError.

    Cheers for the links though.


  • Registered Users Posts: 597 ✭✭✭bambam


    definitely grab a profiler, I'd recommend JProbe - you can get a demo of the full version I think for 10 days. HAve a poke around and see what code is creating lots of objects and/or how big objects are.

    Also you can explicity set the min and max heap size using vm args, here's an eg of min 20, max 100: -Xms20m -Xmx100m


Advertisement