Re: Memory/Object question

From: Date: Mon, 13 Nov 2000 09:44:30 +0000
Subject: Re: Memory/Object question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-24936@lists.php.net to get a copy of this message
The variable's memory is freed when you unset() the variable, or at the end of the function, if the variable was initialized within a function call (by the php garbage collection stuff). If the variable is in the global namespace only unset() can destroy the variable. Objects should be treated as any other variables of any type in this case. Bug Hunter wrote: > So, my next question (whose answer is not critical to the problem) is > when is memory for an object released? Immediately? At the end of a > function call? Or is there a garbage collection period of time, ala > Microsoft Basic 1.0? > > thanks! > bug > > On Fri, 10 Nov 2000, Max Derkachev wrote: > > > Bug Hunter wrote: > > > > > obj["1"] = obj2; > > > > > > If obj["1"] already existed, what happens to it? does it lay around > > > consuming memory, or is it destroyed? > > > > And, concerning your question. If $obj[1] was existed before, it had been > > pointed to a chunk of memory available to php. > > And when you do $obj[1] = $obj2 , the reference count of the chunk it had > > been pointed before is decreased by 1, the > > reference count of the memory object where $obj2 points is increased by 1, > > and while you don't change $obj[1] or $obj[2], > > the same memory is used for both variables. If you change $obj[1], new > > memory for the object of type obj is allocated, and the contents of $obj2 > > is copied there. The reference count of this memory space is increased by 1, > > and $obj[1] now points to this new chunk of memory. > > If there is no any other variable pointing to the chunk of memory where > > $obj[1] pointed before, the memory will be freed to php (but not to the > > system). > > For more information on variable handling and reference counting in php4 > > look through http://www.zend.com/zend/art/ref-count.php > > -- Best regards, Max A. Derkachev mailto:kot@books.ru Symbol-Plus Publishing Ltd. phone: +7 (812) 265-0054, 265-1228, phone/fax: 567-8775 http://www.Books.Ru -- All Books of Russia

« previous php.general (#24936) next »