Java is one of the main design consideration 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 tongue sores 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 tongue sores 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.
(Numbers tongue sores in brackets refer to note that in the case of Java, also referred to memory leak talk, but this is slightly different tongue sores 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 tongue sores the array just use a number of elements. tongue sores 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 to that object, so the garbage collector can not throw it away. should therefore be zero-maintenance object by setting tongue sores 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 tongue sores 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. Imagine 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 trademarks of JNI object 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 tongue sores them. I just made the most prevalent, Sun (Oracle already), Java 2 Platform, Standard Edition JDK is found in Java HotSpot tongue sores virtual machine, I will write, 'the JVM. Good reference for Memory Management in the Java HotSpot Virtual Machine document. The JVM has three main parts: runtime, JIT and garbage collection mechanism performing tongue sores memory management.
The so-called garbage collection mechanism. weak generational hypothesis tongue sores is built. They observed the operation of applications, and noticed the following rules: Most of the objects are short-lived, relatively few old object new object tongue sores reference is
These observations on the majority of applications are true, of course there may be exceptions. That is the most application functions that are often very short-lived, temporal object tongue sores produces during operation, which is really just by running 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 refer to further 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 of this is the object cache, which typically is the oldest object in which more and more objects may be. Those less fond of the garbage tongue sores collector.)
Sun engineers in addition to the JVM built not just one but several garbage collection mechanism. Among them, the JVM will automatically tongue sores be able to choose from but also explicitly be told which one to use. Some garbage collection algorithms in different application
No comments:
Post a Comment