Java thousand ask _07JVM architecture (005) _ Show memory management What's the disadvantage

Source: Internet
Author: User

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:

    1. 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).

    2. 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.

    1. 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.

    2. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.