PHP garbage collector on a resource?

take this simple loop

while(1) {
    $data = file_get_contents('randomfiles.img');
    $resource = imagecreatefromstring($data);

    //> do some image operation and other stuff
    //> continue

    //> not calling imagedestroy($resource);

}

As you can see, I did not call imagedestroy, but I use the same variable ($ resource) to store input imagecreatefromstring();(resource type)

When a new loop starts php GC, automatically delete the previous one $resource?

Consider only PHP 5.3+

thank

+3
source share
2 answers

From http://de2.php.net/manual/en/language.types.resource.php

Release of resources

Thanks to the link counting system introduced with PHP 4 Zend Engine, a resource that no longer has links to it is automatically detected and freed by the garbage collector. For this reason, it is rarely necessary to free memory manually.

. . . . .

+1

, PHP, .

GD, GD. GD lib "" , imagedestroy(). ( , GD Lib , C, PHP).

, imagedestroy(), $resource imagedestroy() .

+3
source

All Articles