Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106106 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6573 invoked from network); 29 Jun 2019 10:40:55 -0000 Received: from unknown (HELO mail-lf1-f52.google.com) (209.85.167.52) by pb1.pair.com with SMTP; 29 Jun 2019 10:40:55 -0000 Received: by mail-lf1-f52.google.com with SMTP id a25so5461787lfg.2 for ; Sat, 29 Jun 2019 00:58:01 -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=Cwr+UbkQco7iQtgpFTCqjUmxoFoO8oZ1OR2dcSX15P8=; b=l4P9J8AnI+6IVOKPbGR7SY0iCqJWb/e+SwkdLCqRdV0lIT+OxENM06yu4L2UNyVXkM SI+N4bHNvX95SHSeiHMVXAzjzvf+enoZw4HogP35+HytLQtwu8COpT65CVvHt9YmAEXi xZxbpOL7G8xdwx3/D3x8EeGeyLrq90DHLMkRqT0YbI3nXQ+84yWkDV+ClyBBw6FDfIAZ Hl25azP3Y8o5yWuajvXiGFey2/BCDkqwLiJ5INC1aEn4FmuTMdwBDatodhoMKeya+vkH EXdfdWEryh/hLxxse66q21zvh85U89K5QDe28f+J1jkCB+hgGLBbGBVLEeSW4CHDY6tW nrGQ== 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=Cwr+UbkQco7iQtgpFTCqjUmxoFoO8oZ1OR2dcSX15P8=; b=hWsG4T0+c92V3INyDa94FIufvuXK1B3FD2dViTA25jL46yzULjkDgmG6Ldrkx0n1uW H+0Znd5yw0Rq7ROv6nyzDzqiVNRZhxa5G4aXEE0Gjv/3LYVkJ9nAPeqQoFfKDjs0l7b4 BVHyrTbZoJKP1t1k0QXoP8lX6faPcM792Dvv4Bk1mTCOLxe6+1xXsqZSSkZxbE6agZcq BHoqx8CL+Fa606PPRW+O56xCuz6bJz1H+vRBn8BMlYw4+blvJXPoL0aZtfq+Nh5LBZrB yvHLx6TmCFV2cmgDz23sobSTAIFFRlBl8Gp07g2J+MRy1j54pN33B/f3fybuN7VVBGu2 +7gA== X-Gm-Message-State: APjAAAV8pv5TfQck8faQKTyvy8ZyNo9hvJ+YqVt2iK7QffEHbysZHh6Q DpoTNynDRNwuaQM6aPvn9VWHTiidP+gg6X1kv1E= X-Google-Smtp-Source: APXvYqw++Vggu4NpAaeUWmfia4sctSSCUJ0EErH/LEFG25wFpdS0KclqxgzZvIpjRmcy9/rSbQtEKvHjznNLBT5Un6Y= X-Received: by 2002:ac2:4a6e:: with SMTP id q14mr7041701lfp.154.1561795080853; Sat, 29 Jun 2019 00:58: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: <003b01d52e49$4db89390$e929bab0$@jhdxr.com> Date: Sat, 29 Jun 2019 09:57:44 +0200 Message-ID: To: CHU Zhaowei Cc: Stanislav Malyshev , Benjamin Morel , PHP Internals Content-Type: multipart/alternative; boundary="000000000000019fc1058c71c1c8" Subject: Re: [PHP-DEV] Memory leak in eval()'d code From: nikita.ppv@gmail.com (Nikita Popov) --000000000000019fc1058c71c1c8 Content-Type: text/plain; charset="UTF-8" On Sat, Jun 29, 2019 at 9:07 AM CHU Zhaowei wrote: > I think we missed the point here. Clousre, or anonymous class, should not > be considered as normal class. We expect normal class existing once we > declare it till end of script. However, for anonymous class, it's usually > used within certain scope, so not only the instances, the class itself > should be included in the GC as well. > I guess the problem here is we didn't GC the space for definition of > anonymous classes. > > Regards, > CHU Zhaowei > As Johannes already pointed out, we cannot garbage collect anonymous class definitions due to the existence of opaque references. A simple example of code that currently works: $obj = eval('return new class {}'); $class = get_class($obj); // create opaque reference unset($obj); // drop last direct reference $obj = new $class; In the end, an anonymous class is essentially a class with a random name and some inline construction sugar, but apart from that does not differ from ordinary classes. (I've also seen some calls to allow syntax like $class = class {}; that would make that even more obvious.) The situation here would be different if we had first-class classes and did not refer to classes by name. But as-is, I don't think garbage collecting anonymous classes is a possibility. Nikita > -----Original Message----- > > From: Stanislav Malyshev > > Sent: Saturday, June 29, 2019 6:52 AM > > To: Benjamin Morel > > Cc: PHP Internals > > Subject: Re: [PHP-DEV] Memory leak in eval()'d code > > > > > > > > On 6/28/19 3:37 PM, Benjamin Morel wrote: > > > That's not a "leak". You create new objects (in this case, > classes), > > > they take memory. > > > > > > > > > Why do they not "leak" memory without eval() then? Replace with > > > `$object = new class {};` and memory usage stays flat. > > > There has do be some kind of garbage collection for these anonymous > classes. > > > > AFAIR this does not create new classes, since it's the same code, and > same code > > means same class. But eval() has new code every time, thus new class. > Generally > > I don't think PHP has any operation that can destroy an existing class. > It won't be > > easy too since you don't know whether there are any objects of this class > > around (unless you're in shutdown). > > > > -- > > Stas Malyshev > > smalyshev@gmail.com > > > > -- > > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, > visit: > > http://www.php.net/unsub.php > > > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --000000000000019fc1058c71c1c8--