It seems you come from a C/C++ background. Java has garbage collection, which implies you only need to erase references to objects and they will be deleted from memory automagically. this is only a reserved word to explicitely access some field or method in the current object (and not accessing another variable with the same name, by example). But it's not a variable nor a reference that counts for garbage collection.
–
heliosAug 23 '12 at 10:55

3 Answers
3

The object will be eligible for garbage collection (effectively deallocated) as soon as it is not reachable from one of the root objects. Basically self-references doesn't matter.

Just make sure you never store references to objects which you won't use any more and the rest will be handled by the garbage collector.

Regarding your edit:

Edit: var1 and var2 has reference to the object of this class, when I delete var1 by doing var1 = null, I want that var2 would be deleted too.

You can't force another object to drop its reference. You have to explicitly tell that other object to do so. For instance, if you're implementing a linked list (as it looks like in your example), I would suggest you add a prev reference and do something like:

if (prev != null)
prev.setNext(next); // make prev discard its reference to me (this).
if (next != null)
next.setPrev(prev); // make next discard its reference to me (this).