Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53993 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99358 invoked from network); 17 Jul 2011 14:20:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Jul 2011 14:20:45 -0000 Authentication-Results: pb1.pair.com header.from=tyra3l@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tyra3l@gmail.com; spf=pass; 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:49914] helo=mail-gx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/72-02120-BBFE22E4 for ; Sun, 17 Jul 2011 10:20:43 -0400 Received: by gxk27 with SMTP id 27so1117237gxk.29 for ; Sun, 17 Jul 2011 07:20:40 -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=PYkT0L6Jq73uejQ5oSLFFRhJ8DsBJ5IlqsvsyocwVGM=; b=kfrBtKQkeZPyjW3aByDxrAibhZZCf9+0pJOlBpI7QMz4e6AWAbCAPSTNPdEEyV0k28 KaHsIkaLDueiblKqZ0qZ2v3Edk38cVO/Ozihp/IbtQq8zSZCAN7SXZHoQFwr0A4OjooT kayZSWypI2odVGHlrJ6soH54rVv0sAW+1vjdw= MIME-Version: 1.0 Received: by 10.236.76.232 with SMTP id b68mr6972045yhe.223.1310912440326; Sun, 17 Jul 2011 07:20:40 -0700 (PDT) Received: by 10.147.38.17 with HTTP; Sun, 17 Jul 2011 07:20:40 -0700 (PDT) In-Reply-To: <4E22DDD0.20105@toolpark.com> References: <4E22DDD0.20105@toolpark.com> Date: Sun, 17 Jul 2011 16:20:40 +0200 Message-ID: To: Lars Schultz Cc: internals@lists.php.net 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 Sun, Jul 17, 2011 at 3:04 PM, Lars Schultz w= rote: > 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. Wha= t 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 t= he > 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 dow= n > 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 functio= n > called: get_ref_count() or something and as I remember, that value is alw= ays > stored in the zval... > > The only other thing that would help would be a callback (or callable) wh= ich > 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 stil= l > 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. --=20 Ferenc Kov=C3=A1cs @Tyr43l - http://tyrael.hu