What is PHP's garbage collection mechanism?

巴扎黑
Release: 2016-11-08 10:55:17
Original
975 people have browsed it

Description: PHP uses a reference counting (garbage collection) mechanism. Each object contains a reference counter. Whenever a reference is connected to the object, the counter is incremented by 1. When the reference leaves the generated space or is set If it is NULL, the counter is decremented by 1. When the reference counter of an object reaches 0, the PHP engine knows that you no longer need this object and releases the memory space it occupies.

                                                                                                                                                          Is the operation a pointer?

No, the & operation establishes a reference pointer, not a pointer. PHP has no concept of pointers. Similar to UNIX file soft links.

What is the difference between the Unset() operation and the assignment of null value operation?

         (a) Unset() only disconnects the reference of this variable to the memory it originally pointed to, making the variable itself an undefined null reference, and decrementing the reference count of that memory by 1 in the symbol table, which has no effect to other variables pointing to this memory. So a Notice is issued when calling this unset() variable. (For a variable unset, it only plays the first time many times)

(b) The assignment NULL operation is quite fierce, it will directly reduce the reference count of the internal existing symbol table of the variable It was recycled, but it is unknown when it was reused. It may be used immediately to store other information, or it may never be used again. But no matter what, all the variables that originally pointed to that memory can no longer operate on the reclaimed memory, and any variable trying to call it will return null.

            Only when the reference count of a piece of memory in the symbol table is 0, the PHP engine will recycle this piece of memory.

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template