Question: Maybe I am out of my mind right now, but I have a question about the scope, or memory allocation, or garbage collection.

The class LinkedIntList has a private field, front, which is a variable of ListNode type (line 4).
The rest of the Linked list is constructed by calling add() function (line 29).

Question: When add() is returned (line 39), are the ListNode created in add(), by new, out of scope and are supposed to be garbage collected? Or they are reserved because front is chain-pointing to them?

```
1 // Simple first version of LinkedIntList with just a constructor
2 // and methods for add and toString.
3
4 public class LinkedIntList {
5 private ListNode front; // first value in the list
6
7 // post: constructs an empty list
8 public LinkedIntList() {
9 front = null;
10 }
11
//....
//....
28 // post: appends the given value to the end of the list
29 public void add(int value) {
30 if (front == null) {
31 front = new ListNode(value);
32 } else {
33 ListNode current = front;
34 while (current.next != null) {
35 current = current.next;
36 }
37 current.next = new ListNode(value);
38 }
39 }
40 }

```

Answer: 
When add() returns, the ListNode created and appended to the list is reserved as it is chain pointed by the front. Parameters passed to a function by value go out of scope when function returns (like value) in this case and cannot be referred from outside. But the ListNode is a new Object creation, it is allocated space in memory and remains even when the function returns.

The garbage collection is done when the references are lost to a memory location. While your program runs your references will be alive so cannot be garbage collected.
An object is not collected by the garbage collector until there's a "live" reference to it, namely until it's reachable (ie. cyclic dependencies do not count). You may want to look at the [mark and sweep](http://www.brpreiss.com/books/opus5/html/page424.html) algorithm.

Your ListNode is an element of the list, so by definition is not unreachable (as long as you keep a reference to the list head).

I suggest you read [this chapter](http://www.artima.com/insidejvm/ed2/gcP.html), that's by far one of the clearest explaination of garbage collection techniques I have found.