Hello,

On Thu, Aug 4, 2011 at 1:53 PM, Ferenc Kovacs <tyr...@gmail.com> wrote:
> so as I see you didn't really addressed the proposed use-case of the
> Weak References, just stated what everybody is aware of: one can cache
> and free objects "manually" without the need of Weak References.
> and while that is true, I still think that this could be a great asset
> for creating high quality components.

I myself oppose WeakReference in java and I do not see my opinion
changing for PHP ... unfortunately I think WeakReference's are even
nastier in PHP because of it's error handling. You see it is very
common when weak references are used in java too follow one of two
paradigms, fall through with NPE's, or state/null checks. With PHP,
you may not "test" the validity of a weak reference simply by
accessing it, you will get a uncatchable fatal error. So in PHP your
only option when consumers are obtaining weak reference handles, is to
check their validity before use, whether that is a call into some
registry, or a null check of the reference itself, whatever.. it still
leads to checks to make sure that reference wasn't collected. This
added complexity in the WeakReference consumer makes me unable see any
purpose through the inconvenience and unpredictability they bring.


> btw. it was suggested before, but I really think, that it would be a
> good idea to have a register_ function which would allow you to pass a
> callable, which will be called when the memory usage reaches a given
> value.
> that would make a good addition to resolve some of use cases mentioned
> in this thread.

I use ticks to do this in a CLI daemon I wrote, worked out pretty
well. Not saying a specialized function isn't needed but I think ticks
aren't to far from convenient to require such.

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to