note 98719 added to function.unset
| From: | Anonymous at osu1 dot php dot net | Date: | Fri, 02 Jul 2010 14:20:06 +0000 |
| Subject: | note 98719 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170654@lists.php.net to get a copy of this message | ||
further I realized that an object, when getting detroyed, does care about destroying variable in
object space visibility but not those in local visibility, be aware of the found pattern:
class release_test{
private $buffer;
private $other_object;
public function __construct(){
$this->other_object=new other_object_class();
}
public function __destruct(){
//note that you always have to unset class objects, in order to get the resources released
unset($this->other_object);
}
public allocate_mem_A(){
$this->buffer=file("/tmp/bigfile");
}
public allocate_mem_B(){
$buffer=file("/tmp/bigfile");
}
public allocate_mem_C(){
$buffer=file("/tmp/bigfile");
unset($buffer);
}
public allocate_mem_D(){
$this->other_buffer=file("/tmp/bigfile");
}
}
//this does not lead to a resource problem
$A=new release_test();
$A->allocate_mem_A();
$A->__destruct();
unset($A);
//this DOES lead to a resource problem
$B=new release_test();
$B->allocate_mem_B();
$B->__destruct();
unset($B);
//this does not lead to a resource problem
$C=new release_test();
$C->allocate_mem_C();
$C->__destruct();
unset($C);
//this does not lead to a resource problem
$D=new release_test();
$D->allocate_mem_D();
$D->__destruct();
unset($D);
----
Server IP: 192.35.244.50
Probable Submitter: 90.146.133.211
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/98719
Del: integrated -- https://master.php.net/note/delete/98719/integrated
Del: useless -- https://master.php.net/note/delete/98719/useless
Del: bad code -- https://master.php.net/note/delete/98719/bad+code
Del: spam -- https://master.php.net/note/delete/98719/spam
Del: non-english -- https://master.php.net/note/delete/98719/non-english
Del: in docs -- https://master.php.net/note/delete/98719/in+docs
Del: other reasons-- https://master.php.net/note/delete/98719
Reject -- https://master.php.net/note/reject/98719
Search -- https://master.php.net/manage/user-notes.php