note 98692 modified in function.unset by danbrown
| From: | danbrown@php.net | Date: | Thu, 01 Jul 2010 13:50:34 +0000 |
| Subject: | note 98692 modified in function.unset by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-170627@lists.php.net to get a copy of this message | ||
unset($class_object) does not release resources allocated by the object. If used in loops, which
create and destroy objects, that might easily lead to a resource problem. Explicitly call the
destructor to circumvent the problem.
<?php
//this causes a resource problem
for($f=0;$f<10000;$f++){
$my_class_object=new my_class_name();
unset($my_class_object);
}
//this releases the resources allocate by the object
for($f=0;$f<10000;$f++){
$my_class_object=new my_class_name();
$my_class_object->__destruct();
unset($my_class_object);
}
?>
--was--
unset($class_object) does not release resources allocated by the object. If used in loops, which
create and destroy objects, that might easily lead to a resource problem. Explicitly call the
destructor to circumvent the problem.
//this causes a resource problem
for($f=0;$f<10000;$f++){
$my_class_object=new my_class_name();
unset($my_class_object);
}
//this releases the resources allocate by the object
for($f=0;$f<10000;$f++){
$my_class_object=new my_class_name();
$my_class_object->__destruct();
unset($my_class_object);
}
http://php.net/manual/en/function.unset.php