What is the garbage collection mechanism of PHP?

Source: Internet
Author: User

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?

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.