I know lots of question have been asked about Garbage Collection and I have gone through them, but I still have have some doubts.
If we cannot force the JVM fo
1) System.gc()
works more often than not. What people mean when they say you can't force garbage collection is that that JVM knows more about the state of memory than you, you can't force garbage collection if the JVM knows it's not a good time to do it.
2) I don't believe user generated classes will make it into perm gen (although I could be wrong), it exists to store meta information such as classes and interned strings (pre Java 7) etc which are always required by the JVM.
3) Static variable are references by the class
they're declared on. Classes are stored in permanent generation so by their very nature static variable will always be referenced so it makes sense to also have them in perm gen.
4) Yes.
Edit from comments: Garbage collection is never done on permanent generation. Am i right?
Not quite. Garbage collection is complicated! The perm gen is far less volatile than the rest of the heap and it's highly likely that the objects there will reference others in the lower spaces. I think the behaviour of garbage collection and perm gen is dependant on the version of Java you're using, I believe newer versions will also garbage collect the perm gen, which makes sense since Java makes a lot of use of proxy objects.