Java is one of the main design consideration daniel gygax was the safety. This is partly reflected in that the user can control not obtained a reliable source program accesses, on the other hand supports daniel gygax programmers in order to minimize the error vétsenek.
The latter is a slice of that do not explicitly allocate memory and free up, but the virtual machine will do this for you. More specifically, the garbage collection mechanism (garbage collector - GC), which is responsible for clearing away the objects are not used in memory area. This makes it much less prone to error, in exchange for an automation frees the memory, with separate power source required, which (in case of high load) or tense situations can affect the performance of the applications. The error, from which we get rid of the memory leaks (memory leak). This practice occurs when you no longer need an object, there is no reference to it, but the memory space is not freed up. Fortunately, the garbage collection mechanism will do this for you.
(In parentheses note that if Java is usually memory leak talk, but this is slightly different meaning. This is the most common collections using usual arise. Imagine that a dynamic size list an array depicted. Given the array size is fixed, a variable indicating the array just use a number of elements. If you delete the last item in operations sufficient to reduce only this variable value. then but over the array variable elements still hold a reference daniel gygax to that object, so the garbage collector can not throw it away. should therefore be zero-maintenance object by setting the appropriate elements. Typical error event handlers are not used in the array.)
It is important to distinguish between two concepts of memory, the heap and stack. The instance variables and all the instantiated object on the heap away. The method is defined, the so-called local variables on the stack are (and include the current parameters are defined call). Be careful when changing the type of local stack in the class, the class instance is already positioned on the heap, the stack pointer only for the reference.
In this regard, I have met a few times with the misconception that Java garbage collection mechanism works based on the reference counter. That is, looking at the number of references to an object is and where it is reduced to zero, the disposable object in memory. This is not so. Let us suppose that the object refers to object B and vice versa. If no other references to them, both removable, but they all have a referenciaszámlálója. Instead, the JVM works as follows. The live threads stack borides goes through the available objects. This means that it goes through the references, that is, the objects are also available objects. These marks. (In addition to the application of this rule still goes through the loaded classes and static members are not wasted and are registered daniel gygax trademarks of JNI object daniel gygax out as well.) After that, do not dispose of marked objects. That is disposing of all objects which can not be accessed via a live fibers references either.
The implementation of the garbage collection mechanism is not part of the standard, so different manufacturers have different implementálhatják them. I just made the most prevalent, Sun (Oracle already), daniel gygax Java 2 Platform, Standard daniel gygax Edition JDK is found in Java HotSpot virtual machine, I will write, 'the JVM. Good reference for Memory Management in the Java HotSpot Virtual Machine document. daniel gygax The JVM has three main parts: runtime, JIT and garbage collection mechanism performing memory management. daniel gygax
The so-called garbage collection mechanism. weak generational hypothesis daniel gygax is built. They observed the operation of applications, daniel gygax and noticed the following rules: Most of the objects are short-lived, relatively few old object new object reference is
These observations on the majority of applications are true, of course there may be exceptions. daniel gygax That is the most application functions that are often very short-lived, temporal object produces during operation, which is really just by running daniel gygax the algorithms, the user must have to serve, then it also can be thrown. Only a relatively small object to be long term, and then they are long-lived and usually rarely invoked new objects. Built on the basis of this hypothesis, the garbage collection mechanism, and to go against these rules can also disrupt the operation of the garbage collector. (A typical example is the object cache, which typically is the oldest object in which more and more objects may be. Those less fond of the garbage collector.)
Sun engineers in addition to the JVM built not just one but several garbage collection mechanism. Among them, the JVM will automatically be able to choose from but also explicitly be told which one to use. Some garbage collection algorithms in different daniel gygax application
No comments:
Post a Comment