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
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to