Can anyone explain how to free the memory in PHP script after a block of code is executed?
I am using PHP5 on apache server
How to release memory in PHP
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
You don't need to worry about it for the mostpart. PHP does its own garbage collection much like other high-level languages, however, you can call unset(). Before you call unset() however, set the value of variable to null because PHP may not remove it from memory at the time you call unset(), it will simply clear it from the namespace.
- Maugrim_The_Reaper
- DevNet Master
- Posts: 2704
- Joined: Tue Nov 02, 2004 5:43 am
- Location: Ireland
Just be careful setting null when a variable is an object before unsetting. There's times where you just want to destroy an object reference to reuse the variable name without effecting other references to the original memory value. I suppose knowing the difference is one of those key pieces of information you need, esp. for PHP5.