Search code examples
eclipsepluginssizeheap-memory

Monitoring Eclipse-plugin heap size *programatically*


I know we can monitor heap size manually by ,

"Show heap status" under Window -> Preferences -> General

So is there anyway to say automatically grab the highest memory used in my eclipse plug-in? This would be convenient to me because my plug-in could run for a long time and monitoring manually is not feasible.

Thanks


Solution

  • You have here a Simple Heap Size Monitor;

    long total = Runtime.getRuntime().totalMemory();
    long free = Runtime.getRuntime().freeMemory();
    

    Launched in a thread and log the total and free memory in a file.

    If you encapsulate that in an eclipse plugin you could launch a custom eclipse with this activated by default and recording what you need.


    Another (more simple) technique would be to attach to your eclipse session a JConsole configured to log what it monitors into a file.

    Low Memory detection at www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/1564119.jpg

    JVMStat (espacially jstat) can be a good solution too.