Leak Examples

eostermueller edited this page Jan 7, 2017 · 6 revisions

This page shows heapSpank in action.

Exhibit A

This screenshot shows one piece of code, with and without a memory leak. See how LKY% goes to 100%? Quick Memory Leak Detection

Exhibit B

Perhaps this is the most common memory leak -- filling up a container that is never cleared out. Compile and run this yourself -- should just take a minute to watch how heapSpank shows you the exact class name (MemLeak) of the culprit.

package com.post.memory.leak;

import java.util.Map;

public class MemLeak { public final String key;

public MemLeak(String key) {
    this.key =key;

public static void main(String args[]) {
    try {
        Map map = System.getProperties();
        for(;;) {
            map.put(new MemLeak("key"), "value");
    } catch(Exception e) {


taken from here.

Exhibit C

This stackoverflow question shows a number of different examples of memory leaks. I've got it on my todo list to package these up nicely for display and heapSpank demos.

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.