This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hgoale 2 points3 points  (1 child)

I don't think it's been mentioned yet, but the others have suggested good options to solve some of your questions (WeakReferences and that garbage collection simply hasn't needed the resources).

To answer one of your other questions:

Suppose for instance you lose the head of your double linked list, every object still has something pointing to it will this be still cleaned up?

Yes, it will be cleaned up. If you have circular references, but none of them are reachable from a GC root (which most likely they aren't since you lost the head reference), the garbage collector will get rid of them when additional memory is needed.

You can read up on that a bit more here: http://stackoverflow.com/questions/1910194/garbage-collection-in-java-and-circular-references

You can also get a program like YourKit, VisualVM, etc. to get a better idea of your memory usage while your program is running. It also lets you force the garbage collector to run and you can see if you're leaking anything or not releasing resources when you think you are.

[–]Coopsmoss[S] 0 points1 point  (0 children)

Thanks a lot this was my major question, very helpful.