Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116908 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 75295 invoked from network); 22 Jan 2022 15:06:35 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Jan 2022 15:06:35 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 162D5180382 for ; Sat, 22 Jan 2022 08:18:20 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 22 Jan 2022 08:18:19 -0800 (PST) Received: by mail-wr1-f47.google.com with SMTP id f17so5503205wrx.1 for ; Sat, 22 Jan 2022 08:18:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :references:from:in-reply-to:content-transfer-encoding; bh=+CLseZ2d8H3hxNHtQ8k01HExnDfd+b/iTUw9/hXR8Ao=; b=Fgc1rXI63cTKPMmThFDeIcicAihxXQuqC5ujZkzcgXsQy9of6MCbFKaZ7hpSm2+0SD VCgFSNu4BggtFkHfix1jnK5JmgonQsLee1vrpeNeNvTDJ6SZ/2QC3S2kLYPFRaYFPKt3 tTIPKnZ6lelLweJa1WcXFdII8rLvP53y15a7/iZ2gAbiE1DBfeGK487qRSA7PCOJmhZn Cl9Kj6jqU02hFGK3nHqpwLHEPtbfcMZYrgkvhjH74GBktDtxT+4td5DC/+8znXfeYVAW hxrDtRga6xpGNAtTPmvr7xvGv1mA2IRXn4Ha1U0VNkXLIyouiHopRJ7N3zI+4GeUrXbO UjgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=+CLseZ2d8H3hxNHtQ8k01HExnDfd+b/iTUw9/hXR8Ao=; b=6bFwhuCGyuuT4jM1JTAT9CApj0GQv27cbKHMi30Lmj020UQCKxkYaFH1WO6o8aFmtZ VVzkZzieIJ14drs/7xLvUXbpAQzMdeFEy+dweA8niJBMQyyPcZjC4m49eeEoiLKyFbzS yYnewjdM6FINmyQgIRtB04XqFpGRLY3Yv6tB1bR32AxDcUfovKYp46DC3dYPZUytGtDN 1H/mhCp9ANEcnYhT9tPDfEXSZGA4I1rP4buhfEFR8Bi+83UI2S1oA6FfU3nrBuSCA94+ VRA4CPo+G1gKKQn7+epkt0jDmJpo9mCbVPEAg4kdY8j41+T4X9GGNFHBcpa0Jmweuqf4 VmEA== X-Gm-Message-State: AOAM5308c0o3XiETWk+nh1HNl+vI2TrPt9i0xeNRXPc+kR/HZ8MEjbuN +Bn+D9GC69+SI5rQ6hijnP6kZ0w7+hg= X-Google-Smtp-Source: ABdhPJxs8Oztu/2j2x5US/vqmWTGjRuOZ6VqNJ9AFuzFLZJi1DdpjiesKQ0sh8aNX5wlgIHynoQ8DA== X-Received: by 2002:a5d:6d8a:: with SMTP id l10mr8221537wrs.490.1642868298391; Sat, 22 Jan 2022 08:18:18 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id i12sm12125195wrf.102.2022.01.22.08.18.17 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 22 Jan 2022 08:18:17 -0800 (PST) Message-ID: <0bcb3e32-9afe-8957-7aa8-ea70f4308407@gmail.com> Date: Sat, 22 Jan 2022 16:18:16 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Content-Language: en-GB To: internals@lists.php.net References: <7ea94d3b-7f1f-b604-b94a-781e0b992c69@gmx.de> In-Reply-To: <7ea94d3b-7f1f-b604-b94a-781e0b992c69@gmx.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: Weak Closures From: rowan.collins@gmail.com (Rowan Tommins) On 22/01/2022 15:30, Christoph M. Becker wrote: > If you trigger the garbage collector manually (i.e. call > gc_collect_cycles() after unset($callback)), the loop terminates right > away. I'm not sure why it doesn't without manually triggering the GC. Most values are freed as soon as their refcount reaches zero, which obviously won't happen for circular references, so an additional algorithm is needed for those. This "cycle collection" algorithm is relatively expensive, so doesn't run every time a possible candidate is found, but only when a list of candidates reaches a particular threshold. The algorithm is outlined in the manual, although it looks like the constant 10000 mentioned there has been replaced by an adaptive threshold (which can be inspected with gc_status()): https://www.php.net/manual/en/features.gc.collecting-cycles.php If you measure memory usage while running the example code in a loop, you should see it slowly growing and then periodically dropping each time a cycle collection is run. That's why gc_collect_cycles() exists - if you _know_ you've created circular references, you can tell the engine to find and free them immediately, rather than waiting for the next pass. Regards, -- Rowan Tommins [IMSoP]