"Reprint" on the garbage collection mechanism

Source: Internet
Author: User
Tags garbage collection variables requires
Reproduced from the "Rain Forum"
Original: Software_young

----------------------Reprint started------------------------
The so-called garbage collection mechanism, refers to the memory and the various variables or the target memory used in the release and recovery mechanism.

The history of software development is the history that the software is huge, the manpower is gradually difficult to control and the technical requirement of the developer is gradually reduced.

Many earlier software, are written in assembly language, assembly is machine code mnemonic mode, so, with the Assembly programming, the actual is the machine code programming. It requires programmers to be very familiar with the machine, otherwise it is difficult to produce a useful program.

At that time the programmer, first of all, if the iron Abacus, need to fully understand the state of the machine's operation, the brain of the CPU on the value of each register, State Register state, the stack of BP, SP, memory allocation and release and other things are very clear to do. He mastered the use and release of all the resources of machines (even virtual machines), so there was no such thing as a garbage collection mechanism. Programmers can be said to be advanced robots, he manages everything.

With the development of software technology, high-level language began to appear, software has become increasingly large, the main high-level language has a dedicated to the allocation and release of memory and variables, goals (for target-oriented programming language) functions or functions.

Programmers use them to manage the allocation and release of memory. But gradually, the advanced robot also feel difficult to cope with, so there is the problem of memory loss, is memory allocation after forgetting to release.

In general, the operating system records the resources used by the process and releases those resources at the end of the process. But if the process runs for a long time, or never ends (host and minicomputer often run year-round), the operating system has no opportunity to release these resources in time, resulting in loss of system memory. The loss of system memory has accumulated to a certain extent, strange things should have appeared.

The problem is actually a comparison of the complexity of the brain and computer. Unfortunately, the human brain is doomed to lose to the computer (in some ways). This requires the system to provide a mechanism to unify the management and recycling of rubbish.

The garbage collection mechanism of different languages and systems is different.

C language does not actually have garbage collection mechanism, all depend on programmer and operating system. If you write a program that forgets to free up memory and runs for a long time, the trouble comes. And if the compiler itself has a problem with the library function, it's even scarier. Borland's C + + compiler often has this problem, the industry many people know, so few people dare to use it to big software.

The C + + language provides garbage collection in the class's destructor, and the programmer decides to release those resources, and when the program calls a destructor of a class, the garbage collection executes and completes. This is actually still the way programmers control.

Java provides a separate garbage collection mechanism that requires no programmer intervention to determine when garbage collection is to be done by a Java virtual machine. Of course, programmers can force the garbage collection mechanism to work immediately under certain circumstances by invoking several methods below System.GC (specific search).

The implementation is divided into two parts, one part is how to determine what is garbage, and the other part is how to recycle.

In the first part there are two kinds of methods, the first is the so-called reference counting method, the reference count of zero is rubbish, this method is very simple, but can not handle the problem of mutual reference; the second is the so-called method of the following, because Java all things are nothing more than two categories, goals and targets, the target exists in the heap, In the non-target existence stack, the stack's advanced back out way determines that there will be no garbage problem, and all the targets are the generations of object. From scratch, you can determine who the good guys are (someone who wants it, there is a leader), who is the bad guy (no one wants it, no leader), and the villain is dealt with.

The second part is divided into two major categories, synchronous and asynchronous.

The so-called synchronization is at a certain moment all the processing paused, for garbage collection, and then continue to suspend the processing. This method is simple, but it can cause turbulence in the performance of the system.

The so-called asynchronous is divided into two steps, the first pause processing, marking, and then partition the system, according to the partition to deal with the villain, the advantage of this method is the system performance of the bumps will be reduced, the disadvantage is due to synchronization problems, may pass the bad guys.

The general use of synchronous methods on the PC, because the application of the PC is generally not too large, the impact of the system turbulence is not big. Asynchronous methods are generally used on as/400, and as/400 system features (multiple subsystems) combine to minimize deficiencies, and of course as/400 can also use synchronized methods, which can be set in WebSphere for as/400.

. NET garbage collection mechanism and Java is very similar, here is not to repeat.


Software_young Editor at 2002-02-01 13:55
----------------------Reprint End------------------------

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.