Re: Memory/Object question
| From: | Bug Hunter | Date: | Fri, 10 Nov 2000 19:41:27 +0000 |
| Subject: | Re: Memory/Object question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24697@lists.php.net to get a copy of this message | ||
Thanks! this solves the problem of long term running of a script, and
allow you to do daemons running under php. I like it. PHP3 was unsuited
for this unless you were extremely careful.
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
>