On Sun, Jul 17, 2011 at 3:04 PM, Lars Schultz <lars.schu...@toolpark.com> wrote:
> I too would welcome a solution to this problem, I've run into it several
> times already and always had to use a semi-satisfactory solution. I hadn't
> heard about weak-references before, and I generally like the concept. What I
> am not so sure is wether this makes everything alot more complicated for
> users who do not know/care about the problem or the solution. Of course the
> impact on those users depends on the actual solution.
>
> I came at the problem from a different angle and came to a different
> solution: If I could get the refcount on a certain object, and kept the
> object stored centrally in one list, I'd know that if the refcount is down
> to 1 (or some other constant) that the object ist not in use anymore. I
> believe that this would be quite a simple PHP addition...a simple function
> called: get_ref_count() or something and as I remember, that value is always
> stored in the zval...
>
> The only other thing that would help would be a callback (or callable) which
> is triggered by PHP reaching a certain memory-limit, absolute or relative.
> Then I could clean up memory according to my own business-logic...
>
> This way, PHP would not feature something totally new, but one could still
> solve the problem with some work.
>
> Do I make any sense at all? Am I missing the point? Anyway, this is an
> interesting problem.
>
> Cheers.
> Lars
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

we have debug_zval_dump but it is hard to use correctly (see the
notes) and xdebug has xdebug_debug_zval which is slightly better, but
it is not part of the language.
with weak references, you wouldn't need to worry about keeping a count
of the refcount only check the valid() method.

for your last paragraph: that's totally unrelated to weak references,
but you could achive what you want through memory_get_usage() +
unsetting your unnedid variables and maybe calling
gc_collect_cycles().
btw. if I remember correctly, somebody requested a non-fatal callback
when memory limit is reached callback functionality, I have to look
that up.

-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

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

Reply via email to