edu.mssm.crover.memtest
Class LeakTester

java.lang.Object
  |
  +--edu.mssm.crover.memtest.LeakTester

public abstract class LeakTester
extends java.lang.Object

Test a class use scenario for memory leaks. Memory leaks appear when unused instances are not properly unreferenced. Being still referenced, these instances cannot be garbage collected. It is generally difficult to find memory leaks and they are easy to introduce. The following methode is used by LeakTester to detect important memory leaks.

  • A full garbage collection (Runtime.gc() is called until no memory can be freed) is done.
  • The free memory is recorded.


    Constructor Summary
    LeakTester()
               
     
    Method Summary
    static long freemem()
               
    static void fullGC()
               
    abstract  void init()
              Initialize the experiment.
     void interact(java.lang.String message)
               
     void main(java.lang.String[] args)
              Run the test.
     void printDetails()
               
     void setInitialUse(int initial_use)
              Sets the number of times use() will be called before actually testing for memory leaks.
     void setInteractive(boolean flag)
              Sets the interactive mode on/off.
     void setRepeatExperiment(int times)
              Sets the number of times use() is called before the conclusion that no memory leak occurs can be assumed.
    abstract  void use()
              Override to provide the use scenario.
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Constructor Detail

    LeakTester

    public LeakTester()
    Method Detail

    main

    public void main(java.lang.String[] args)
    Run the test.


    interact

    public void interact(java.lang.String message)

    printDetails

    public void printDetails()

    freemem

    public static long freemem()

    init

    public abstract void init()
    Initialize the experiment. Set the intial number of use() and the number of experiments here.


    use

    public abstract void use()
    Override to provide the use scenario. A scenario should do the following:
  • Allocate instances from the class(es) to test,
  • Use this objects,
  • Try to release the references from this objects.


  • setInitialUse

    public void setInitialUse(int initial_use)
    Sets the number of times use() will be called before actually testing for memory leaks.


    setInteractive

    public void setInteractive(boolean flag)
    Sets the interactive mode on/off. When the interactive mode is enabled, the LeakTester print messages on the console that indicate the steps that have been executed so far. It then waits for an input from the user on the console. The user must press return before the test proceeds. This gives the opportunity to select the exact condition when to create heap snapshots. See hat from Javasoft.


    setRepeatExperiment

    public void setRepeatExperiment(int times)
    Sets the number of times use() is called before the conclusion that no memory leak occurs can be assumed.


    fullGC

    public static void fullGC()


    Copyright @ 2003 Mount Sinai School of Medicine. All Rights Reserved.