performance, memory & objects
| From: | Erik Price | Date: | Thu, 27 Jun 2002 14:54:25 +0000 |
| Subject: | performance, memory & objects | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-104172@lists.php.net to get a copy of this message | ||
Since we are on the topic of objects with PHP, what is the best way to free the memory being used by an object?
A lot of examples use unset($objReference). But when freeing the memory used by a large string, it's best to assign that string's reference variable to an empty string, ($str = "";) according to "Programming PHP" by Tatroe and Lerdorf. I was surprised that this book didn't mention freeing memory used by objects (or if I'm wrong, please point me to the right page).
Here's a sample from my script I'm working on right now... is assigning the object's reference variable to "null" redundant or not worthwhile?
// $result = a MySQL result resource
$photos_string = "";
while ($row = mysql_fetch_assoc($result)) {
$photo_obj = new PhotoItem($row['photoitem_id']);
$photos_string .= $photo_obj->display();
$photo_obj = null;
unset($photo_obj);
}
// do something with $photos_string
Erik
----
Erik Price
Web Developer Temp
Media Lab, H.H. Brown
pricee@hhbrown.com