Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53981 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34903 invoked from network); 16 Jul 2011 10:34:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2011 10:34:12 -0000 Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.170 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.160.170 mail-gy0-f170.google.com Received: from [209.85.160.170] ([209.85.160.170:57167] helo=mail-gy0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B1/00-34288-719612E4 for ; Sat, 16 Jul 2011 06:34:12 -0400 Received: by gyb13 with SMTP id 13so912690gyb.29 for ; Sat, 16 Jul 2011 03:33:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=SouyOMElKVvREqA3nOlFnnIjyqpSxO9GN2mCkCauiho=; b=QEPbMLdNtMn+kULoOXEX8odgLfgzllfbsY2/S4YI0kLrtbLKuLnlAZ68HDEYyvIn8p al9P1e2UtN/1pVdtH75hJ8FQsfZeFYZ5oqG+GTP+e7igjGtXTO4l8zccQum41GOhK9C5 fPibd/MAPj3znIGskCkTAO8iqxTL1hUo+M21k= MIME-Version: 1.0 Received: by 10.236.76.232 with SMTP id b68mr5981021yhe.223.1310812436407; Sat, 16 Jul 2011 03:33:56 -0700 (PDT) Received: by 10.147.38.17 with HTTP; Sat, 16 Jul 2011 03:33:56 -0700 (PDT) In-Reply-To: References: Date: Sat, 16 Jul 2011 12:33:56 +0200 Message-ID: To: RQuadling@gmail.com Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] weak references From: tyra3l@gmail.com (Ferenc Kovacs) On Sat, Jul 16, 2011 at 12:14 PM, Richard Quadling wr= ote: > On 14 July 2011 20:42, Ferenc Kovacs 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#fea= tures.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 =3D -1]) > > $ttl =3D -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. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu