Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Memory profiler for Java?

  • 24-08-2004 02:30PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 584 ✭✭✭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