Where is the reference count error?

Source: Internet
Author: User

Just now look at the cloud wind blog "object and resource management" (trackback address: http://blog.codingnow.com/mt/mt-tb.cgi/140), quite different opinions.

First of all, C ++ is not C # And not Java. If you have to open a thread in C ++ to perform GC, it is better not to use C ++. C ++ programmers can precisely control the time when objects are released, which is just the strength of C ++. For example, I have a socket object, I can ensure that the socket is closed during the analysis, but in C #, it is very painful not to do so, because the ghost knows when the object will be destroyed.

Second, are you afraid to forget to reduce the reference count? In this article, I also admit that the C ++ syntax can perfectly enable you to automatically increase the count when referencing an object, rather than decreasing when you don't need it. Now there is such a good syntax, why not? Does the compiler make mistakes more easily than programmers?

Third, the original article says, "You can schedule a regular time in the main thread to scan all objects and delete the objects to be deleted. The usual delete operation is just a simple mark operation. "Who will perform this mark operation? For example, I put an object pointer in an STL container, when the STL container is destroyed, does it dare to mark it? How does it know that no one is referencing this object? What is the difference between this mark and delete?

Fourth, there seems to be nothing in the original article that can prove the irrationality of "using the code generated by the compiler (automatically) to ensure that the reference count is correct, it is just that the compiler implicitly generates some code (more target code ). Is that the reason? What modern languages need to do is to let the compiler do more and let programmers make fewer mistakes. In contrast, would we prefer to increase the amount of source code (and error-prone? Think of a statistical document, saying that a line of Perl code is equivalent to what six lines of C code can do, while a line of C ++ code is equivalent to about 2.5 lines of C code, that is, the more advanced the language is, the less the source code is. This is justified. At least it should be said that the number of target code he will generate should not be considered, in addition, the efficiency of the code generated by C ++ is very close to that generated by C, so that our service programs will not be moved because of the structure and analysis.

Fifth, using a thread to regularly scan all objects is a waste of space and time. If an object can remember how many times it has been referenced, it does not have to be managed by another manager.

So where is the reference count error?

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.