Re: Manual unset and GC
| From: | Ilija Tovilo | Date: | Mon, 10 Mar 2025 21:53:24 +0000 |
| Subject: | Re: Manual unset and GC | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126701@lists.php.net to get a copy of this message | ||
Hi Vinicius
On Mon, Mar 10, 2025 at 5:15 PM Vinicius Dias <carlosv775@gmail.com> wrote:
>
> > TL;DR: Does setting a variable to
null (or even
> > unseting it) have **any** effect if that's the last instruction
> > of a function?
As others have pointed out, it is _almost_ completely unobservable.
There are two small differences:
1. When the variable is a reference, $var = null; will write null to
the reference, rather than the variable. The "out of scope cleanup"
would be closer to an unset() rather than = null.
2. = null / unset() runs destructors in the scope of the child, while
the cleanup on function exit executes in the parent scope.
https://3v4l.org/obAgg
But in terms of garbage collection, there's no value that would be
cleaned up with an explicit unset() that wouldn't also be cleaned up
when leaving the function. The arguments from your co-workers seem to
rely on a faulty understanding of the engine.
Ilija