If an SplObjectStorage instance destructs while still having some objects attached, does it implicitly detach the objects first, or does a memory leak result by the SplObjectStorage's references to those dangling objects? I'm trying to determine if userland code to "detach anything that's left before destructing" is necessary to prevent such a memory leak.
$storage = new SplObjectStorage();
$x = new stdClass();
$y = new stdClass();
$storage->attach($x);
$storage->attach($y);
$storage = null;
// did not explicitly detach $x and $y... does $storage's destruction do it?
// or do the zval counts on $x and $y now off by one?
$x = null;
$y = null;
// at this point, are there two dangling references to $x and $y,
// simply because $storage did not dereference from them before destroying itself?
The simple answer is: it should free those two objects.
If this is not the case, this should be considered a bug.
To test: create a class with a destructor, and ensure that it's called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With