Your last two lines there where you are adding the vertices and edges is where you are eating up your heap. Each time you throw your int into the add first, it is being boxed up in an object and thrown on the heap. The question is getting around it... hmmm....
You could try instead of using an arraylist of linkedlists instead create an arraylist of a custom object which wraps an int array and of course the support functions for adding/removing values much like a list does. The idea is that these objects can be stored in the array list and instead of manipulating objects like a linkedlist does, it would be handling primatives which are not stored on the heap. You would also be able to control how slim your custom object is, providing only the most basic functionality required instead of the bloat of supporting all the other functions a linkedlist has with it.
The idea would be to reduce the footprint each object has and instead of a list of boxed up Integer references you would instead have a managed int array.
I can't guarantee it would work, but it would be worth exploring.
This post has been edited by Martyr2: 9 May, 2008 - 04:15 PM