Introduction to PHP garbage collection mechanism (gc)

Release: 2023-04-08 13:44:02
forward
2782 people have browsed it

Introduction to PHP garbage collection mechanism (gc)

PHP compilation principle:

ze (zend engine) calls the lexical analyzer to remove spaces from the PHP code, split it into tokens after comments, and ze calls syntax analysis The processor then processes the token to form opcode, which exists in the form of op array, and finally executes op array to output the result.

When a PHP thread ends, all memory space currently occupied will be destroyed. So if this thread does not end, how to reclaim the memory?

refcount: Reference technology device, which can be understood as the number of pointers pointing to the container.

is_ref: Whether it is referenced (can only be 0 or 1)

Assignment process:


        
Copy after login

Reference process:


        
Copy after login

If there are more If you unset one reference, will is_ref be set to zero? Then won’t a bug appear? Variable containers are still references. So let's take a look:


        
Copy after login

Can unset and assignment null recycle variables? Many people mistakenly believe that these two can recycle variable space. In fact, they are wrong. null only reduces the space occupied by variables. From a recycling perspective, the container still exists.


        
Copy after login

Recommended:PHP video tutorial

The above is the detailed content of Introduction to PHP garbage collection mechanism (gc). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:oschina.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!