Skip to content

Instantly share code, notes, and snippets.

@DiveInto
Created November 12, 2012 05:19
Show Gist options
  • Save DiveInto/4057644 to your computer and use it in GitHub Desktop.
Save DiveInto/4057644 to your computer and use it in GitHub Desktop.

Revisions

  1. DiveInto revised this gist Nov 12, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion MLeaks.java
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ public static void main(String[] args){
    Thread thread = new Thread(){
    public void run() {
    try {
    URLClassLoader cl = new URLClassLoader(new URL[]{new URL("file:/Users/mmliu/workspace/MLeaks/bin/")});
    URLClassLoader cl = new URLClassLoader(new URL[]{new URL("file:/path-to/MLeaks/bin/")});

    System.out.println(cl.toString());
    Class<MLeaks> tmpClass = (Class<MLeaks>) cl.loadClass(MLeaks.class.getName());
  2. DiveInto revised this gist Nov 12, 2012. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions MLeaks.java
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@
    ```java
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;
    @@ -35,5 +34,4 @@ public void run() {
    thread.start();
    }
    }
    }
    ```
    }
  3. DiveInto created this gist Nov 12, 2012.
    39 changes: 39 additions & 0 deletions MLeaks.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    ```java
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLClassLoader;

    public class MLeaks {
    static byte[] m = new byte[1024 * 1024];
    static ThreadLocal<MLeaks> tLocal = new ThreadLocal<MLeaks>(){
    @Override
    protected MLeaks initialValue()
    {
    return new MLeaks();
    }
    };

    public static void main(String[] args){
    while(true){
    Thread thread = new Thread(){
    public void run() {
    try {
    URLClassLoader cl = new URLClassLoader(new URL[]{new URL("file:/Users/mmliu/workspace/MLeaks/bin/")});

    System.out.println(cl.toString());
    Class<MLeaks> tmpClass = (Class<MLeaks>) cl.loadClass(MLeaks.class.getName());

    tmpClass = null;
    } catch (MalformedURLException e1) {
    e1.printStackTrace();
    } catch (ClassNotFoundException e) {
    e.printStackTrace();
    }
    }
    };

    thread.start();
    }
    }
    }
    ```