NYCPHP Meetup

NYPHP.org

Fwd: Re: [Zend Engine 2] protected

Hans Zaunere zaunere at yahoo.com
Thu Jul 11 19:33:38 EDT 2002


It seems I've been forwarding more than making real posts lately (aside
from an incisive HTML question :).  But this seems like some valuable
info right from the "source":

--- Zeev Suraski <zeev at zend.com> wrote:
> >     Since when does PHP have garbage collection?
> 
> Depends on what you mean by garbage collection.  PHP uses an
> aggressive 
> garbage collection since forever (that is, v3.0).  That means that
> anything 
> that is no longer used, it gets deallocated.  This model became
> stronger in 
> v4.0, which also supported automatic destruction of resources as soon
> 
> as  they are no longer referenced.
> 
> The only problem with that model is that due to the dynamic nature of
> PHP, 
> there are situations when a certain object may have a longer lifetime
> than 
> necessary.  It works in most cases:
> - Local variables (which may point to scalar/array/object/resource
> values) 
> get destroyed/deallocated as soon as you return from their
> encapsulating 
> function
> - Overwriting the last reference of a variable will immediately 
> destroy/deallocate the value it points to.  So, for instance, if you
> have a 
> main loop in a program that has $obj = new foo(...); in the beginning
> of 
> the loop body, every time $obj gets overwritten with a new object -
> the old 
> one gets destroyed.
> 
> >     All based on the assumption there's no garbage collection
> >     like Java has it.
> 
> In many ways it's much better than Java's garbage collection.  In
> PHP, if 
> you do unset($foo) or $foo = null, you can know for sure that $foo
> got 
> destroyed (assuming the value it pointed to isn't referenced anywhere
> else 
> in the program).  In Java, you're at the mercy of the garbage
> collector.
>


__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com



More information about the talk mailing list