WideImage logo

WideImage Wiki : HandleOwnership

MainPage :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register
SourceForge.net Logo
Most recent edit on 2007-03-03 15:20:02 by GasperKozak

Additions:

CategoryDoc




Edited on 2007-03-02 18:49:15 by GasperKozak

No differences.


Edited on 2007-03-02 18:48:50 by GasperKozak

No differences.


Edited on 2007-03-02 18:48:17 by GasperKozak

Additions:
Sometimes this behaviour is unwanted. When you want to have the control of the image resource even after the object is destroyed, you have to explicitly tell the object to release it:

Deletions:
Sometimes though, this behaviour is unwanted. When you want to have the control of the image resource even after the object is destroyed, you have to explicitly tell the object to release it:



Oldest known version of this page was edited on 2007-03-02 18:47:38 by GasperKozak []
Page view:

Handle ownership

By default, every image object owns its handle (which is a gd resource). By owning it, it's also responsible for destroying it properly. This is implemented via PHP's destructors -- when an image object is destroyed, it will automatically call imagedestroy() on its image handle. This means you don't have to destroy the images explicitly, they're destroyed when an image object is no longer used.

Example

$img = wiImage::load(...);

// get the handle
$handle = $img->getHandle();

// handle is valid
imagepng($handle);

// destroy the object
unset($img);

// handle isn't valid anymore
imagepng($handle);


Releasing a handle

Sometimes though, this behaviour is unwanted. When you want to have the control of the image resource even after the object is destroyed, you have to explicitly tell the object to release it:
$img = wiImage::load(...);
$handle = $img->getHandle();

// tell the object to release the handle
$img->releaseHandle();

unset($img);

// handle is still valid
imagepng($handle);


But now you have to explicitly destroy the image resource. It's the price you pay.
imagedestroy($handle);
WideImage - an Object-Oriented PHP Image Library for Image manipulation
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.4412 seconds