Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106107 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 23961 invoked from network); 29 Jun 2019 12:31:53 -0000 Received: from unknown (HELO mail-io1-f41.google.com) (209.85.166.41) by pb1.pair.com with SMTP; 29 Jun 2019 12:31:53 -0000 Received: by mail-io1-f41.google.com with SMTP id s7so17779316iob.11 for ; Sat, 29 Jun 2019 02:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tVdBtGt0IacRR2Oaio1HpunKujjv6Fs1kzjto3+8ZZc=; b=Oa04erLhwJYp/PgxxArNBRjIs78mVXdsle9+8aUZf7e5f1fNLeUSsrUvQVfZHrMmKY uo3tib40uJShKGiUUwdetZkhwNFW3tTsFWhYOZJP/bQ2dUbehWHqFQGYE1fH0lFrKE6/ SvCI6XuU9uWqB2oQNTM3QpDaODVZixxIr4uyr3GQKRCt/Kg1mX1gSvxmHDYQGwffLwzK mOsMRzjoiZNDA2Cb/ye/1BSFTjBWTQ8NKpghhhoUFriykyfwzxZSmDZQAXG+EljKT+fO M6kQaX1gv//Z3087/DQRpmOFFRxnv42pkTWmXfzQXOHqhGmtcUCimOoY8rEP2E+oEdpk EP/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tVdBtGt0IacRR2Oaio1HpunKujjv6Fs1kzjto3+8ZZc=; b=e2o9DDwYQOGkMbUCOcfLvlHQZKuMdKpHFxr2jcEQKZR9mwG/hegbuMgri5+S05AZ3c Xz+N5CGxX4ja36U7pMsIscjJUZO4PrOCxdgWNVX0qbFoqoNIAW29bPGsXl3u83kAsXNt oe021olpVc205UFHE6On+6muErZFjJ5qHlF0fkk1tSK3hZxzXl0qpOQ1aDyhc/gXKfmZ Yh36kvBha+GtPvg0OUCx804IXnlXdK7m4NffxI/np7whPG/WiipU9KCdweIxI3eDTzzb LnBRK74PBd9DX65mNjzj4eowLXOGBUgSmbdxWW+vILBCjHS1vpjP9jpB7O89Yxec5HQV PAPw== X-Gm-Message-State: APjAAAUTwjwrDERKriDeLSIpyZCht2cztO7qsE8vOia6xgJEDhzy1/my XDkHJmmO3NYnMjtvM6a+wujw/Q+MLScmVa1bF6M= X-Google-Smtp-Source: APXvYqyIZxwFyplYc1VYOVYm8ifYIRFLqaCWaF1ey0uzPylFce17+UMc6APum3KFCwAWYgW4ckGQnuQ/RHBLt76Siy0= X-Received: by 2002:a5d:9282:: with SMTP id s2mr6642051iom.36.1561801740491; Sat, 29 Jun 2019 02:49:00 -0700 (PDT) MIME-Version: 1.0 References: <8f07c0dc-f9a5-8c76-1d48-0fac762bfc4f@gmail.com> <92dba455-17df-41dd-c523-bb0db3c12078@gmail.com> <003b01d52e49$4db89390$e929bab0$@jhdxr.com> In-Reply-To: Date: Sat, 29 Jun 2019 11:48:49 +0200 Message-ID: To: Nikita Popov Cc: CHU Zhaowei , Stanislav Malyshev , PHP Internals Content-Type: multipart/alternative; boundary="000000000000f3a041058c734df1" Subject: Re: [PHP-DEV] Memory leak in eval()'d code From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000f3a041058c734df1 Content-Type: text/plain; charset="UTF-8" > As Johannes already pointed out, we cannot garbage collect anonymous class definitions due to the existence of opaque references. I still don't understand *why*, then, the memory stays flat when the new class does not happen in eval(): ``` for ($i = 0; $i < 1000000; $i++) { $object = new class {}; if ($i % 1000 == 0) { echo memory_get_usage() . "\n"; } } ``` I checked get_class() for all instances returned, **it's always the same class name whether it's called from eval() or not**, so this code should only ever create a single class in memory, right? Why the leak with eval()? > $class = get_class($obj); > $obj = new $class; Interesting. Can this behaviour be relied upon (is it documented?), or is this an implementation detail that may change at any time? Thank you, Ben --000000000000f3a041058c734df1--