The following code shows how to de-allocate a color for an image.
<?php $white = imagecolorallocate($im, 255, 255, 255); imagecolordeallocate($im, $white); ?>