PHP features garbage collection mechanism 3--performance considerations

Source: Internet
Author: User
In the previous section we have simply mentioned that recycling may have subtle performance effects on the root, but this is when comparing PHP 5.2 with PHP 5.3. Although in PHP 5.2, the record may be slower than the root at all, and other modifications to PHP run-time in PHP 5.3 reduce this performance penalty.
There are two main areas that have an impact on performance. The first is the memory footprint savings, and the other is the increase in execution time (run-time delay) when the garbage collection mechanism performs memory cleanup. We will study these two areas.
Savings in memory footprint
First, the entire reason for implementing the garbage collection mechanism is to save memory consumption by cleaning up the variables referenced by the loop once the prerequisites are met. In PHP execution, garbage collection is performed once the root buffer is full or when the Gc_collect_cycles () function is called. In, the following script shows the memory footprint of PHP 5.2 and PHP 5.3 respectively, excluding the basic memory that PHP itself occupies when the script starts.
Example #1 Memory Usage Example

<?php      class Foo      {public          $var = ' 3.1415962654 ';      }        $baseMemory = Memory_get_usage ();        for ($i = 0; $i <= 100000; $i + +)      {          $a = new Foo;          $a->self = $a;          if ($i% = = 0)          {              echo sprintf ('%8d: ', $i), Memory_get_usage ()-$baseMemory, "\ n";          }      }  ?>

The above is the PHP characteristics of garbage collection mechanism 3--performance considerations of the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.