Re: weak references
| From: | Lars Schultz | Date: | Sun, 17 Jul 2011 13:04:16 +0000 |
| Subject: | Re: weak references | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-53992@lists.php.net to get a copy of this message | ||
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