What is php's garbage collection mechanism? Solution

Source: Internet
Author: User
What is php's garbage collection mechanism? As the question... tencent pen questions searched online ..., I only know the garbage collection mechanism of the session, but I don't understand it. I hope to be a master ., in other manuals, it is mainly because the resources are subject to post-natal spam issues, but there is a count function after PHP4. if the resources are not occupied, they will be automatically released. in PHP, what is php's garbage collection mechanism when no variable points to this object?
As the question...

Tencent pen questions searched online...

------ Solution --------------------
Only the session garbage collection mechanism is known.
------ Solution --------------------
Don't understand, help top, look forward to master.
------ Solution --------------------
In other manuals, resources are mainly post-natal spam, but PHP4 has a count function. if resources are not occupied, they are automatically released.
------ Solution --------------------
In PHP, when no variable points to this object, this object becomes garbage. PHP will destroy it in the memory. this is the GC mechanism of PHP to prevent memory overflow.

When a PHP thread ends, all memory space currently occupied will be destroyed, and all objects in the current program will be destroyed at the same time. GC processes generally start to run with each SESSION. gc aims to automatically destroy and delete these files after the session file expires.
------ Solution --------------------
Executing these functions can also be used for recovery.
_ Destruct/unset/mysql_close
------ Solution --------------------
Php's garbage collection mechanism does not need to be considered by programmers,
You only need to close unused resources in time and unset the variables that occupy large resources in time.

------ Solution --------------------
Php has a clear gc processing time setting for the session
Session. gc_maxlifetime
------ Solution --------------------
I personally think every request is a process.
------ Solution --------------------
I leave a trace
------ Solution --------------------
Discussion
Reference:
When a PHP thread ends, all memory space currently occupied will be destroyed, and all objects in the current program will be destroyed at the same time. GC processes generally start to run with each SESSION. gc aims to automatically destroy and delete these files after the session file expires.


Thread? Does PHP support multithreading?

Is every Tag to create a thread?
Or every file produces a thread?

Or is there only one thread?

Thank you!

------ Solution --------------------
Discussion
Php has a clear gc processing time setting for the session
Session. gc_maxlifetime

------ Solution --------------------
Is it possible to process the garbage in memory?
First, as a script language, PHP releases the memory occupied by variables at the end of the page.

If there is garbage, it is the non-single-piece mode caused by multiple calls to the same file by the overall program in the framework.

Therefore, when coming out, it is necessary to use the _ once reference and the single-piece mode when declaring the class. There are also simplified logic and so on.

If you want PHP to manage its own memory and spam. Haha. It seems that PHP still cannot do it. for the destructor, ANDI is very clear in his book. Optional.

Memory management is generally considered by desktop programs. PHP still has to do something about memory management.


------ Solution --------------------
Learning
------ Solution --------------------
Haha ~~, Learning!
------ Solution --------------------
I don't understand. I have read the garbage collection mechanism of JavaScript, and PHP has never paid attention to it!
------ Solution --------------------
I remember that using reference counting and write-time replication to manage the memory is also the main mechanism of PHP memory management.
------ Solution --------------------
There are always so many terms for recruitment in China, so many theories need to look at the specific capabilities during development.

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.