Le 30/06/2010 09:20, Andrew Kennedy a écrit :

So, what do people think would be the best and simplest way to test this
leak is fixed? Or am I over complicating this for myself before I've had
enough coffee?

I admit I don't remember seeing a unit test for a memory leak. This is usually verified once by a profiler. I see two approaches to write such a test:
- generate a heap dump and inspect it
- if the test can get a reference on the object that leaks, the garbage collection can be verified by a WeakReference combined with a ReferenceQueue

public void testMemoryLeak() {
    Object leakingObject = getLeakingObject();

    ReferenceQueue queue = new ReferenceQueue();
    WeakReference reference = new WeakReference(leakingObject, queue);
    leakingObject = null;

    // so some operations supposed to dereference the object

    System.gc();

    assertTrue(reference.isEnqueued());
}


Emmanuel Bourg

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to