Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54344 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36900 invoked from network); 4 Aug 2011 09:08:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 09:08:26 -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.161.170 as permitted sender) X-PHP-List-Original-Sender: tyra3l@gmail.com X-Host-Fingerprint: 209.85.161.170 mail-gx0-f170.google.com Received: from [209.85.161.170] ([209.85.161.170:40594] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/53-18399-9816A3E4 for ; Thu, 04 Aug 2011 05:08:25 -0400 Received: by gxk27 with SMTP id 27so1044273gxk.29 for ; Thu, 04 Aug 2011 02:08:23 -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=lv0XxX8JtmkLA2YOh+t6akE/lZdtJCCDv/eiBDE5WOU=; b=F0jYQ2ElwNrfnhBcqTOhQs6diOFMtuFaAFWlv9fCx+bNSpgiH+ZS7HvHWKUn47UsLW T4OJqF31bdGHy0DUAevdB2qK0txFbE1NqVObBjNPYZqZyHu6QIeROiy4jqZ+ybnYasoD eQTmlwnPhhJQYN7z0lQAkdKdB386KCNsizyyw= MIME-Version: 1.0 Received: by 10.146.30.26 with SMTP id d26mr463398yad.25.1312448901579; Thu, 04 Aug 2011 02:08:21 -0700 (PDT) Received: by 10.147.82.17 with HTTP; Thu, 4 Aug 2011 02:08:21 -0700 (PDT) In-Reply-To: <4E3A5A50.30707@lsces.co.uk> References: <4E3898B0.40809@sugarcrm.com> <4E38EC0C.9080304@lerdorf.com> <4E38FA2E.4030605@lsces.co.uk> <4E38FC67.9090200@toolpark.com> <4E39E89F.8060605@sugarcrm.com> <4E3A3643.2070305@toolpark.com> <4E3A4793.2070209@sugarcrm.com> <4E3A5A50.30707@lsces.co.uk> Date: Thu, 4 Aug 2011 11:08:21 +0200 Message-ID: To: Lester Caine Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Weak References From: tyra3l@gmail.com (Ferenc Kovacs) On Thu, Aug 4, 2011 at 10:37 AM, Lester Caine wrote: > Stas Malyshev wrote: >>> >>> I am open to any suggestions how I could solve my problem without >>> WeakReference or zval-refcount (short of keeping a ref-count in >>> userland). >> >> Do not keep object references, keep object IDs. This would make your >> code a bit more verbose and a bit slower, but weak refs would >> essentially do the same anyway. > > Like you Stas I am having trouble understanding what the problem is ... > > On one 'project' I'm playing with I build a tree of genealogical referenc= es > in memory, all identified by their unique_id. If the person has already b= een > loaded, then it simply uses the existing reference for that element of th= e > tree. If there is a change to data for some reason the 'cached' record is > deleted so that it has to be re-read from the database next time it's > accessed ... if it is accessed at all. Persons are all class objects ... = so > deleting is just marking the object as invalid at which point ( I hope ) = the > underlying data is dropped. if you have gc enabled, and noone else references that object, then it will be freed next time when the gc runs. what weak references are trying to solve, that if you create such a Registry, as you do, your object will always have at least one reference (your Registry holds them), so gc won't collect those. with weak references, you can lazy load your Person records as you do, but every People record which only referenced through Weakrefs will be garbage collected on the next gc run. collecting the garbage will happen if the gc root buffer is full, or if you manually call gc_collect_cycles. http://www.php.net/manual/en/features.gc.collecting-cycles.php --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu