How does PHP handle memory usage compared to other programming languages like Java?

PHP typically consumes less memory compared to Java due to its lightweight nature and the fact that it is a scripting language. However, PHP does not have automatic memory management like Java's garbage collection, so it is important to manually manage memory usage in PHP to prevent memory leaks and optimize performance.

// Example of manually managing memory in PHP
$largeArray = range(1, 1000000); // Create a large array
unset($largeArray); // Unset the array to free up memory