aspose file tools*
The moose likes Java in General and the fly likes gc() of method area Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "gc() of method area" Watch "gc() of method area" New topic
Author

gc() of method area

Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
Hi Cindy,
I am reading (I shall not tell when&where), as you told me, JVM specs.
from 3.5.4 of JVM specs:
The Java virtual machine has a method area that is shared among all Java virtual machine threads. The method area is analogous to the storage area for compiled code of a conventional language or analogous to the "text" segment in a UNIX process.
......
The method area is created on virtual machine start-up. Although the method area is logically part of the heap, simple implementations may choose not to either garbage collect or compact it. This version of the Java virtual machine specification does not mandate the location of the method area or the policies used to manage compiled code.

If method area is created on VM start-up, then when it is, supposedly, have to be gc()-ed?
...be gc()-ed by whom?
Does it mean that if an object is not gc()-ed by/inside JVM, it is not released with the death of JVM?
What does exactly garbage collector make: is the memory released by it, is released to operating system or still confined for use of JVM? In other words, in stack we also have a pointer moving, but does it mean that without special measures, objects (or memory there) on stack are not released(specs are telling only about gc() of the heap)?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
The method area as a rule is maintained by the JVM by using loading and unloading techniques, not the gc (although as you see - some implementations may choose to use the gc() for portions of the method area). For most classes that you and I use, they are loaded by the bootstrap classloader, and stay in the method area until the JVM is brought down, at which time the memory is released.
If a class is loaded by a custom classloader, then it may specifically unload the class.
The gc's job is to get rid of objects that no longer have references. That memory is released back to the JVM to be used as heap space. Stack usage (which typically is not part of heap space but may be) is aligned to Frames in the JVM, and there is a distinct Frame for each method invoked. When the method is over the stack memory is released to the JVM.
When the JVM comes down all memory relating to the JVM is released. The only memory to be concerned about is related to those resources that may have been allocated using JNI calls. It is necessary to be sure that such things (like IO files etc) are specifically released when they are no longer used. Typically that is done by using a finalization method.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
Originally posted by Cindy Glass:
The gc's job is to get rid of objects that no longer have references.

This is the main question that is torturing me.
If there is no references, who and how does know that memory chunk (occupied, really in the past, but now even not referenced) cannot be reused. Just overwritten.
What does it mean: to release, to garbage-collect?
It is memory, can be virtually even on hard disk.
When I delete the file (some kind of non-OO object) in OS (operating system), the entrance/reference in file allocation table (FAT) looses first letter that tells to OS that the memory "can be reused" (what is the same as "is released"). The memory now can be re-used/overwritten, or file may be undeleted (just a reference, or even just a first letter in the name of file recuperated). It may be undeleted even if some chunks of the file was overwritten! Partly lost file...
Why if JVM knows that there is no more references there is a need of anything else (called garbage collection). Again, I even do not care why. I just try to understand what does it mean to release the memory (just go and write to it!).
The connected question: why it is so important to have object/variable initialized? what a disaster may happen if the memory will be used without initialization, i.e. overwriting of those chunks of memory?
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
I still wonder
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
What does it mean: to release, to garbage-collect?
This is OS dependant.
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
Can you explain over any platform/OS.
I know a couple of dozens well
I really would like to know and cannot get to it from reading
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Nope. This SHOULD be an implementation detail that a java programmer should never be exposed to.
Guennadiy VANIN
Ranch Hand

Joined: Aug 30, 2001
Posts: 898
Cindy,
thank you very much.
But I feel unsatisfied (I am not programmer).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: gc() of method area
 
Similar Threads
String Literals and GC
Garbage collection and var scope
method area
Java heap remaining high
are statics inherited?