J
J
JastaFly2021-07-16 14:41:28
PHP
JastaFly, 2021-07-16 14:41:28

PHP unset function?

Good day to all! Digging into the legacy, I noticed that the unset function is often used there to delete arrays or objects, if this function is absent or present, the result does not have any effect, which means that unset is used to clear memory. But why?!?? Why not leave this job to the garbage collector?!??

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2021-07-16
@usdglander

The garbage collector needs to know what to clean up. unset just indicates what data is no longer needed and can be removed from memory. If you need to clean up the memory before the garbage collector takes care of it, then use the assignment
$data = null;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question