VIPS OOPS Unit 1 Garbage Collection
VIPS OOPS Unit 1 Garbage Collection
Young Generation
Young generation memory consists of two parts, Eden space and survivor
space. Shortlived objects will be available in Eden space. Every object starts its
life from Eden space. When GC happens, if an object is still alive then it will be
moved to survivor space and other dereferenced objects will be removed.
import java.util.LinkedList;
import java.util.List;
public class GC { public static void main(String[] main)
{
List l = new LinkedList(); // Enter infinite loop which will add a
String to the list: l on each // iteration.
do { l.add(new String("Hello, World")); }
while (true); } }
Output: