When will PHP class objects be destroyed? How to solve

Source: Internet
Author: User
When will PHP class objects be destroyed? There is a problem: when the object will be destroyed automatically, and the script will be destroyed automatically after execution. However, if I create an object a in a function, so when this function is executed, will object a be automatically destroyed ?, Reference: When will the class object of http://school.itzcn.com/special-spid-30.h PHP be destroyed?
There is a problem: when the object will be destroyed automatically, and the script will be destroyed automatically after execution. However, if I create an object a in a function, when this function is executed, will object a be automatically destroyed?

------ Solution --------------------
Refer:
Http://school.itzcn.com/special-spid-30.html
The description above is more detailed,
Hope to help the landlord.
------ Solution --------------------
To be accurate, it is recycled after the garbage collector runs .....

Normally, no problem. The function will be recycled after it is completed...


If you are interested, run this program :(

Class {
Function _ construct (){
$ This-> B = new B ($ this );
}
Function _ destruct (){
$ This-> B->__ destruct ();
}
}

Class B {
Function _ construct ($ parent = NULL ){
$ This-> parent = $ parent;
}
Function _ destruct (){
Unset ($ this-> parent );
}
}

Function test (){
For ($ I = 0; I I <10000; $ I ++ ){
$ A = new ();
// $ A->__ destruct (); // check whether this line of comment is different from that of no comment.
}
}

Test ();
Echo number_format (memory_get_usage ());


The results of the above line are completely different from those of the above line.



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.