Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Do need use imagedestroy() before unset Array in PHP?

So i got array like this:

$array = [];
$array[0] = imagecreatetruecolor(10, 10);
$array[1] = imagecreatetruecolor(10, 10);
...
$array[1000] = imagecreatetruecolor(10, 10);

All elemets in array above is GdImage. So, do i need to do something like this before unset array to free memory?

foreach($array as $value)
{
   imagedestroy($value);
}
$array = null;
unset($array);

or just do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

$array = null;
unset($array);

>Solution :

Reference https://www.php.net/manual/en/function.imagedestroy.php says:

8.0.0 This function is a NOP now.

So, there’s no need to call it. Just unset() or set to null as you asked. The garbage collector will free the memory.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading