Each language has its own automatic garbage collection mechanism, so that <SPAN class = 'wp _ keywordlink'> Program </span> Members do not have to worry too much about program memory allocation, however, in OOP, some objects need to be explicitly destroyed to prevent program execution memory overflow. <Br/> 1. Garbage collection mechanism in PHP (GC) <br/> when no variable points to this object in PHP, this object becomes garbage. PHP will destroy it in the memory. This is the GC mechanism of PHP to prevent memory overflow. <Br/> when a PHP thread ends, all currently occupied memory space will be destroyed, and all objects in the current program will be destroyed at the same time. GC processes generally run with each session. GC aims to automatically destroy and delete session files after they expire. <br/> 2. _ destruct/unset <br/>__ destruct () destructor, which is executed when the garbage object is recycled. <Br/> unset destroys the variable pointing to the object, rather than the object. <Br/> 3. Session and GC <br/> due to the working mechanism of PHP, it does not have a daemon thread to regularly scan session information and determine whether it is invalid, when a valid request occurs, PHP will use the global variable session. gc_probability and session. gc_divisor value to determine whether to enable a GC. By default, session. gc_probability = 1, session. gc_divisor = 100 that is to say, there is a 1% possibility to start GC (that is to say, only one GC in the 100 requests will start with one of the 100 requests ). <br/> GC is used to scan all session information and subtract the last modification time of the session from the current time, which is the same as that of the session. the gc_maxlifetime parameter is compared. If the survival time exceeds gc_maxlifetime (24 minutes by default), the session is deleted. <Br/> however, if your web server has multiple sites and multiple sites, the GC processing session may have unexpected results, because: When GC is working, sessions of different sites are not distinguished. <br/> how can this problem be solved? <Br/> 1. modify the session. save_path, or use session_save_path () to save the session of each site to a dedicated directory. <br/> 2. the GC startup rate is provided. Naturally, the GC startup rate is improved, and the system performance is also reduced. This is not recommended. <Br/> 3. In the <SPAN class = 'wp _ keywordlink '> Code </span>, determine the survival time of the current session and delete it using session_destroy.