How to unload 'execution Busy memory' with Php ? function 'unset(...)'

Joined
Sep 4, 2022
Messages
158
Reaction score
16
Hello Php coders !

when you have wide Php scripts,
not enough memory can crash your script if they reach the high limit of memory, then your script is 'out of memory'.


in Php purposes,
it exists one function to unload explicitely some vars.

let's see :
PHP:
<?php

// 'arrays' , 'objects' , 'php native objects' and wide 'string' could be heavy weighted.
// used in a loop , or along one script.
// the Php script RAM amount required is on a 'growth' by every loop achieved.

$obj = new lambda_but_RAM_glutton(); // ::new var, an object.

while( $waiting_for_loop_end() ){

   $obj->_add_collection( $big_collection ); // ::using the var , with increasing ram used mulitple times.

}

// $obj takes more and more memory at every loop

// by one function : 'unset($___)'; , you will operate one explicit 'free() on memory'

unset($obj); // ::destruction of the var because of no more need for all following instructions

// the '$obj' var will be deleted from memory in use,

// the available memory for the script will gain __free space__ , that's so useful !

?>

when you have no more needs with vars along your script, 'unset( $var ) ;' will save free memory.
It's a high skill habits .

PHP:
<?php

// syntaxt for several VARS :
unset( $some , $multiple , $vars , $to_free , $from_memory ) ;

// syntax for one VAR :
unset( $var ) ;

?>




It's more :

  • 'explicit memory management',
  • higher quality of your Php scripts,
  • safer execution within your Php scripts.

one right good habit !

Try it !
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top