Click to enter _ more _java thousand ask
1, display memory management what is the disadvantage
Manual memory management is generally referred to as display memory management, which shows that memory management often occurs in two situations:
Reference suspension
When a memory space that is being used by a reference variable is freed during redistribution, the reference variable is suspended (the referenced object no longer exists).
If this is a dangling reference variable that attempts to manipulate the original object, the execution result is unpredictable because the memory space of the object itself has been manually freed (no longer exists).
Memory leaks
A memory leak occurs when some reference variable no longer references the memory object, and the memory that the object originally occupies is not released.
For example, the memory allocation of a linked list, because the manual allocation of memory is improper, just let the reference variable point to the memory space of an element, so that the memory space of these elements in the program is in an unreachable state, and these objects occupy the memory can not be reused, this time a memory leak occurs.
Once this happens in the program, it consumes the system's available memory until the available memory is exhausted. For a computer, a memory leak is very serious and can cause a program that would otherwise run normally to be interrupted directly because of insufficient memory. Exception with Java is not a level of error.
For display memory management, manually managing memory costs are too high and risky. So most of the purely object-oriented languages provide the memory features of the language itself: automated memory management. Java, for example, provides a garbage collector (garbage COLLECTOR,GC), and automatic memory management provides more reliable code that allows the memory to be properly distributed within the program.
2. What are the benefits of automatic memory management in Java?
Automatic memory management (implicit memory management) in Java solves problems with display memory management: reference hanging and memory leaks.
For reference hanging
The JVM hides the management of memory, so there is no release of the memory space in use, and no reference hanging occurs.
For memory leaks
Once an object is not referenced by any reference variable, which means that these objects become unreferenced objects in the JVM's memory pool, the garbage collector reclaims the memory of those objects (which, of course, needs to satisfy some rules, see here: [What Java garbage collection mechanism is][2]).
[2]:
Java thousand ask _07JVM architecture (005) _ Show memory management What's the disadvantage