Is it more efficient to disable the properties of an object in destructor?


Assume a object that has properties with big amount of data, Is it more efficient to unset properties in destructor? or let php free the allocated memory by that object?

class A {
    protected $foo;
    protected $bar;
    protected $baz;

    public function __construct()
        $this->foo = big_amount_of_data();
        $this->bar = reference_to_a_big_object();
        $this->foo = data_from_big_file();

    public function doProcess()
        // do something

    public function __destruct()
        // Should I do this?

Ok so to make it simple : No, you shouldn't really do that.

You'd better let PHP do what it wants with your object and its variables when you destruct it if it's all about unsetting variables to get back some memory.

1) You're never sure that unsetting variables with unset will give you back the used memory directly. It could be instant (and still, not really, it just depends on when the garbage collector will decide to do his job), it could be a few time later or at the very end of your script anyway thanks to the garbage collector. It's not a sure way to get the memory back, that's it.

2) There will be no change on variables accessibility