Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There is hardly a reason to do so. All memory will be freed when the script terminates.</p> <p>But, if you allocate a lot of memory it might be useful to do so, especially if your scripts take a little longer to run. The memory will be freed immediately and can be used by other scripts. </p> <p>But like you say, it takes code to do so, making your code less clear. So only do this if you have allocated large chunks of data that you don't longer need, like file contents read from disk or big arrays with query results. Don't go freeing integers and don't worry about your message string either. :)</p> <p>{edit after comments} </p> <p>My answer was mainly focused to using PHP for website scripting. Of course if you are creating long running scripts, especially if the amount of memory they allocate is very variable, then of course it can make sense to free up memory, although even those scripts run for a limited period of time. </p> <p>I don't think there are many daemons written in PHP that run forever. Most scripts, even those shell scripts, perform a specific task (if you can call 'rendering a website' or 'migrating a database' specific) after which they end. Within the context of that task it is still quite useless to free up every variable you allocated. This is a big different between scripts like this and programs that might run for a long time, perform the same task over and over again or are completely user-controlled, so you don't know what they will do. And if you do manage to write a long running script or daemon in PHP, other rules apply, because it's another kind of application. But by that time, you won't be searching this answer, because you have gained more than enough knowledge already to know what you're doing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload