tags:

views:

34

answers:

1

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

A: 

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\n being stored in the buffer. An exception will use significantly more than 168bytes (as it stores a backtrace, and other information).

ircmaxell
I've changed the code, there is no output any longer.. The effect is the same :(
Vincenzo
Try doing `echo memory_get_usage()."\n";try{throw new Exception('foo');}catch(Exception $e) { echo memory_get_usage()."\n"; }` It could be because of other internal information (run time, backtrace, etc). Why are you fretting over 168 bytes (I understand from a curiosity perspective, but is it a big deal either way)?
ircmaxell