package org.apache.markt.leaks.rmi;

import java.rmi.Remote;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

import org.apache.markt.leaks.LeakBase;

public class BindingLeakContainerRegistry extends LeakBase {

    public static void main(String[] args) {
        BindingLeakContainerRegistry bindingLeak = new BindingLeakContainerRegistry();
        try {
            LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
        } catch (Exception e) {
            e.printStackTrace();
        }
        bindingLeak.doLeakTest();
    }


    private static final String NAME = "Chat";

    private Remote remoteObject;


    @Override
    protected void createLeakingObjects() {
        try {
            remoteObject = new ChatImpl();
            Chat stub = (Chat) UnicastRemoteObject.exportObject(remoteObject, 0);
            LocateRegistry.getRegistry().bind(NAME, stub);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @Override
    protected void cleanUpLeakingObjects() {
        // TODO: Figure out how to make this work without the reference to
        //       remote object.
        try {
            LocateRegistry.getRegistry().unbind(NAME);
            // Note the following call is not required to prevent a memory leak
            // but not making the call means an additional GC is required to
            // clean up.
            UnicastRemoteObject.unexportObject(remoteObject, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
        remoteObject = null;
    }
}
@@ -216,16 +216,380 @@
 kBase;%0A%0A
+/**%0A * Demonstrates that a web application that uses a container provided RMI%0A * registry will not trigger a memory leak but will require additional GC calls%0A * to clean up.%0A *%0A * TODO: How to force a clean-up when the original remote object is not%0A *       available?%0A *       How to clean up the reference that currently requires the additional%0A *       GC?%0A */%0A
 public c
@@ -1457,115 +1457,8 @@
 ) %7B%0A
-        // TODO: Figure out how to make this work without the reference to%0A        //       remote object.%0A
     

Add Javadoc