What role does the imagedestroy() function play in managing memory usage in PHP scripts that involve image manipulation?

The imagedestroy() function in PHP is used to free up memory allocated for an image resource after it is no longer needed. This is important in scripts that involve image manipulation to prevent memory leaks and ensure efficient memory usage.

// Example code snippet showing the use of imagedestroy() function
$image = imagecreatefromjpeg('example.jpg');

// Image manipulation code here

// Free up memory allocated for the image resource
imagedestroy($image);