PHP as the scripting language is the end of the page to release the memory of the variable. When a PHP thread ends, all memory space currently occupied is destroyed, and all objects in the current program are destroyed at the same time. GC processes are typically run with each session.
The GC is designed to automatically destroy deleted files after the session file expires. In PHP, when there are no variables pointing to this object, the object becomes garbage. PHP will destroy it in memory, which is the GC garbage disposal mechanism of PHP to prevent memory overflow.
Performing these functions can also play a role in recycling
__destruct
unset
Mysql_close
Fclose PHP has a clear GC processing time for the session.
Set Session.gc_maxlifetime If there is garbage, it is the whole program in the framework of the use of multiple calls to the same file, etc. caused by non-single-piece mode. So when it comes out, it is necessary to use the _once reference, using a single-piece mode when declaring the class. There are simplified logic and so on.
And if you want PHP itself to manage memory, garbage management. Oh. As if PHP could not be done, for the destructor, Andi in his book is very clear. Optional, not set No. and the memory management of things are generally the desktop program to consider more.
——————
The following are from official documents
- PHP Manual "Features" garbage collection mechanism
Garbage collection mechanism Table of Contents
- Basic knowledge of reference counting
- Recycling cycle (collecting Cycles)
- Factors to consider in terms of performance
This section explains the characteristics of the new garbage collection mechanism (that is, GC) in PHP 5.3.
Basic knowledge of reference counting
Http://php.net/manual/zh/features.gc.refcounting-basics.php#features.gc.compound-types
Recycling cycle (collecting Cycles)
http://php.net/manual/zh/features.gc.performance-considerations.php
Factors to consider in terms of performance
Http://php.net/manual/zh/features.gc.performance-considerations.php#features.gc.performance-considerations
What is the garbage collection mechanism of PHP?