Why does GC use reference notation?

Source: Internet
Author: User
When I learned JAVAGC, I saw that the reference counting method (ReferenceCounting) was used for PHPPerlPython garbage collection. Why? Is there any reason? JAVA is not. When I learned java gc, I saw that Reference Counting was used in PHP Perl Python garbage collection. Why? Is there any reason? JAVA is not. Reply content:
The reference counting method is used when PHP Perl Python garbage collection is performed,
I remember that Python is not purely a reference count.
Why? Is there any reason?
It is probably because the implementation is simple.
JAVA is not.
It's not a scripting language. Almost no one has ever said, "before asking why, please first ask, isn't it ...... At least V8 is not ...... PyPy does not seem to be ...... Java GC is generational gc, and V8 is also. In general, how to implement gc should be considered in combination with efficiency, complexity, and fragmentation. In most cases, it is easy to consider the script language! Re sort ference counting is the simplest method for garbage collection in the scripting language.
1 reference count, such as cpython
Advantage: objects can be instantly released without gc dependency
Disadvantage: unable to process cyclic references. gc is required to detect cyclic references;
The implementation of virtual machines is complex. You must be careful when adding or subtracting the reference count.

2. Mark the deletion method, such as lua.
Advantage: the virtual machine is easy to implement and does not need to worry about circular references.
Disadvantage: objects cannot be deleted immediately. gc is required to recycle the memory. The reference counter cannot solve the problem of circular reference. The reference count achieves high simplicity but has the problem of circular reference.


Root set scan, no such problem but slow performance.

Therefore, gc usually uses multiple mechanisms to release a portion of the samples and then uses the root set for scanning.

By the way, I have no reference to the counting language. For example, in java, when opening a file, I have to define what I mean in finalize. It is still not fully automated garbage collection...
If you don't close it, you can only listen to gc's destiny, and you don't even know when to close it... The scripting language is not clear. Let's talk about java. It should be slightly different.
In ancient times, no. The reference counting method has a fatal defect and cannot solve the problem of circular reference,
The algorithms used later are all optimized algorithms,
For example, replication and collection are mostly applicable to young generations. (temporary objects have more permanent objects and fewer permanent objects)
For example, Mark clearing and Mark sorting are mostly used in the old generation (more permanent objects and fewer temporary objects)
The words are not very professional.

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.