Php <5.3 garbage collection, is it necessary to set the values ​​of the array null or set the array = null so that all strong elements remain?

therefore I use php 5.2 and need garbage collection, as I deal with very limited resources and large data sets.

from my tests, I saw that unset does nothing until the end of the script (even if I run out of memory), which is a little contrary to the documentation, although I assume that I also read 5.3 Documents, not 5.2 documents, and 5.3 documents look relatively undocumented .

An example of my class’s barebones looks like this:

class foo{
private $_var;

public function __construct(){
  $this->_var = array();
  for($i = 0; $i < 10000000000; $i++){
       $this->_var[rand(1, 100000)] = 'I am string '.$i.' in the array';
  }
}

  public function myGC(){
    $this->_var = null;
  }
}

"myGC()" foreach , , NULL ( , ++), $this → _ var = NULL, , , ?

+1
2

$this->_var = NULL, , $this->_var.

()

echo 'before: '.memory_get_usage().'</br>';
$Test = foo();
echo 'after class instance: '.memory_get_usage().'</br>';
$Test = foo->myGC();
echo 'after unset of _var: '.memory_get_usage().'</br>';
$Test = NULL;
echo 'after unset of object: '.memory_get_usage().'</br>';
+4

myGC() , ?

, unset , . , . - .

class foo{
    private $_var;

    public function __construct(){
      $this->_var = array();
      for($i = 0; $i < 10000000000; $i++){
           $this->_var[$i] = 'I am string '.$i.' in the array';
           unset($this->_var[$i]);
      }
    }
}
$f=new foo();
0

All Articles