How crucial is object destruction in PHP? is it important to destroy objects in PHP after using them? because unlike java, PHP doesn’t have a garbage collector (nothing that I know of)
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t need to destroy objects in the general case, and PHP certainly does have a garbage collector. Moreover, most simple scripts would not even really need one because the whole environment is torn down and rebuilt for every HTTP request; the garbage collector helps those scripts that would run out of memory while serving a single request.
Exceptions to the general case:
You might want to “lose” all references to objects that consume a large amount of memory and/or wrap unmanaged resources; this is usually as easy as
If that was the last reference to
$largeObject, then:gc_collect_cyclesto force garbage collection at any time).Of course all of this does not come into consideration in the typical case of “service a request and then exit”.