This is the code (just a simplification of a real problem):
<?php
echo memory_get_usage() . "\n";
function f() {
throw new Exception();
}
function foo() {
try {
f();
} catch (Exception $e) {
}
}
foo();
echo memory_get_usage() . "\n";
This is the output (PHP 5.3):
630680
630848
What happened with memory (168 bytes lost)? The exception object is not destroyed? Please, help! Thanks
The exception object is destroyed. What’s more likely, is that you have output buffering on, and the added 168 bytes is from the echoed
this is a test\nbeing stored in the buffer. An exception will use significantly more than 168bytes (as it stores a backtrace, and other information).