How does PHP handle memory cleanup for unused variables, objects, and resources, and what factors can affect this process?
PHP uses a garbage collection mechanism to automatically clean up memory used by unused variables, objects, and resources. However, the process of memory cleanup can be affected by factors such as circular references, long-running scripts, and large amounts of data being processed.
// Example code demonstrating memory cleanup in PHP
// Create a large array to simulate memory usage
$data = range(1, 1000000);
// Unset the variable to free up memory
unset($data);