Reputation: 7599
I wrote a little class for storing global variables/functions. My question is - is it necessary to destroy the class object after the script has finished? or will PHP destroy that object itself?
Here's my code:
$web=new c_web("myWeb");
$web->loadTemplate("/!framework/admin/template.htm");
$web->doStuff();
// script has finished - destroying required here?
In case I need to destroy it, how can I do that?
Upvotes: 5
Views: 9770
Reputation: 9703
As @Nanne sayd, if the script finished the memory is released, however in some circumstances you might whant to unset($web); .
Upvotes: 4
Reputation: 400972
No, you do not need to destroy any variable yourself (and an object is a variable) : as soon as your PHP script reaches its end, its variables will be freed, and the correspondig memory released.
Actually, a variable gets destroyed automatically when the end of its variable's scope is reached -- and, when you reach end of script, it's the end of the scope introduced by that script's execution.
Upvotes: 4
Reputation: 64399
If the script finishes, the memory is released. You're ready as is :)
Upvotes: 9