Boring days drives the sanest people do craziest jobs.
Glad I'm not one of them. Still, I benchmarked imagedestroy() and unset() function with a little script:
<?php $cool = imagecreatefrompng('imagefile.png'); echo memory_get_usage(),'<br />'; $timeparts = explode(' ',microtime()); $starttime = $timeparts[1].substr($timeparts[0],1); $cool = imagecreatefrompng('primespiral2000.png'); //imagedestroy($cool); unset($cool); $timeparts = explode(' ',microtime()); $endtime = $timeparts[1].substr($timeparts[0],1); echo bcsub($endtime,$starttime,6),'<br />'; echo memory_get_usage(),'<br />'; ?>
This script proves unset() uses less memory and it's the better choice. unset() result less memory is most likely because unset() actually delete the variable, while imagedestroy() only clean up the image structure inside GD.
$cool = imagecreatefrompng('imagefile.png'); imagedestroy($cool); echo isset($cool); //1 $cool = imagecreatefrompng('imagefile.png'); unset($cool); echo isset($cool); //echos nothing...
Comments
But who said memory_get_usage know about the usage of GD?
Hi,
I really liked your blog! keep on the good job :D
But this time, In your testing script you're assuming that the function memory_get_usage() knows also about the memory being used internally by GD resources, where from you know that?
Could be that since you're unsetting the variable, PHP no more knows about its existence and therefore fooled about the memory usage...
True... this assumption is
True... this assumption is bad...
Post new comment