When are PHP variables released?

angryTom
Release: 2023-02-28 06:08:01
Original
3584 people have browsed it

When are PHP variables released?

When are PHP variables released?

PHP variables are released after the program is executed.

If you are finished using it and want to destroy it, you can use unset to destroy and release

Example: unset($str);

unset and null

$var = null;This method only removes the reference, but does not actually release the memory. The unset method is PHP's built-in method of destroying variables and releasing memory.

But it should be noted that if the reference relationship of the variable referenced by unset(); is still there, then this memory will not be released for the time being. Only when all variables refer to this memory area This freed memory area will be released only after all references are broken.

For example:

Copy after login

Result:272

Copy after login

Result:192

For more PHP related knowledge, please visitPHP中文网!

The above is the detailed content of When are PHP variables released?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn