I think a common inner class memory leak would work. Example taken from the internet:
public class LeakFactory
{//Just so that we have some data to leak
int myID = 0;
// Necessary because our Leak class is non-static
public Leak createLeak()
{
return new Leak();
}
// Mass Manufactured Leak class
public class Leak
{//Again for a little data.
int size = 1;
}
}
public class SwissCheese
{//Can't have swiss cheese without some holes
public Leak[] myHoles;
public SwissCheese()
{
// let's get the holes and store them.
myHoles = new Leak[1000];
for (int i = 0; i++; i<1000)
{//Store them in the class member
myHoles[i] = new LeakFactory().createLeak();
}
// Yay! We're done!
// Buh-bye LeakFactory. I don't need you anymore...
}
}
What happens here is the createLeak() factory method return Leak class and theoretically LeakFactory object is eligible for GC to be removed as we don't keep reference to it. But the Leak class needs LeakFactory to exists thus LeakFactory will never be deleted. This should create a memory leak no matter what Java version you use.