On Sat, Jul 16, 2011 at 12:14 PM, Richard Quadling <rquadl...@gmail.com> wrote:
> On 14 July 2011 20:42, Ferenc Kovacs <tyr...@gmail.com> wrote:
>> To spare the "5.4 features vote" thread from the off-topic discussion,
>> we can continue here.
>> Hannes Landeholm brought this idea up, see
>> http://news.php.net/php.internals/53956 and
>> http://news.php.net/php.internals/53959
>> I would suggest that Hannes create an rfc, and add some examples and
>> introduce the weak references in general and how this can be useful,
>> what problems do they solve (it was discussed in the bugreport, but it
>> wasn't clear as far as I can tell from the comments).
>
> Not being an expert here, so the questions may have obvious answers.
>
> How often does the gc cycle run during a script?

"First of all, the whole reason for implementing the garbage
collection mechanism is to reduce memory usage by cleaning up
circular-referenced variables as soon as the prerequisites are
fulfilled. In PHP's implementation, this happens as soon as the
root-buffer is full, or when the function gc_collect_cycles() is
called. In the graph below, we display the memory usage of the script
below, in both PHP 5.2 and PHP 5.3, excluding the base memory that PHP
itself uses when starting up."
http://www.php.net/manual/en/features.gc.performance-considerations.php#features.gc.performance-considerations.reduced-mem

>
> Can preemptive cleanup actually cause more of a headache?
>
> In reading about weak references on
> http://en.wikipedia.org/wiki/Weak_reference, weak references look like
> a perfect use case for memory limited caches, but I wonder if there
> would be a way of synching a TTL to the weak referenced objects, so
> that they essentially automatically expire (or can be expired and
> expunged). A system controlled TTL for weak referenced objects.
>
> So,
>
> void SplWeakRef::__construct(object $ref, [int $ttl = -1])
>
> $ttl = -1 would allow the object to be gc'd in the normal way, but any
> other value would be a hint to how long the object would be expected
> to last for. If gc happens frequently, then $ttl acts as a limiter and
> I think this could be very useful.

the current implementation doesn't change the way that gc works.
it only stores the reference in such a way, than the gc can free the
object, if nothing else references it.
of course we could improve the gc mechanism, as you suggested, but I
think that would be a more complex and risky, so maybe that would be a
feature-creep for now.

-- 
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