Re: Memory/Object question

From: Date: Fri, 10 Nov 2000 09:08:07 +0000
Subject: Re: Memory/Object question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-24639@lists.php.net to get a copy of this message
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 (#24639) next »