Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106116 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 44796 invoked from network); 30 Jun 2019 00:35:00 -0000 Received: from unknown (HELO mail-lf1-f49.google.com) (209.85.167.49) by pb1.pair.com with SMTP; 30 Jun 2019 00:35:00 -0000 Received: by mail-lf1-f49.google.com with SMTP id x144so6251550lfa.9 for ; Sat, 29 Jun 2019 14:52:15 -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=ps7xQc505Zrzq/TWz1LJVB+PvK4pWwwYPYpqd9D/rD8=; b=tRMUwGiw+cQcN7WHGC164DkiqOP73zx2V4hRB9zmsnG6Dyt/llxwm5zphucjUSqe3F yYYqckYlud03HYtd2YLTZ/lC8+rCCq68D6uOIewgzYNI3DOwqLBeJojZWprewNBmylZ1 Ccq7MzoOnylVDpsD64ivMOYY5BNCrwFmx6P68nmWDeyYcPwAEzE3iyL/8ZlWIzc1iiR0 NrxKYROd/azVzg0MK9nZ6VHmJNp9WXj3WMIrmDe1AtoKevUoLVhqQ9WD4TntWoOvaLMN CDN4bzepuy+poZgSSw3PojsQ59pFZgmShOMK10tjh8CvrkrsPs4iVxQEuvYJjLjuk/dB ZpXQ== 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=ps7xQc505Zrzq/TWz1LJVB+PvK4pWwwYPYpqd9D/rD8=; b=nhMuP2oAA8KTtGIzDDwwpvQn8UcaDA8ZntBuAChfyL0vBIe6sMj4tSErpf2c+RVkVB 6UIbNwYF07LN55I2qY3ec5rnyhFFdGpbeFWfjzHTqItRfA6ySOT515Q4P4sO6udJ3It7 1WZ3ApksdQEbWU16GMGHGIEUSvW8xcL+pe4/JPhAloUcQ+mfdL8tiwinkWsgNN8sxkZe JHGNP8OpiUEHtkZwlHij9a25T8GfAx91o9yp8pip4/fIGpQEUHEV4ecGY54ZmSFbF7jZ XyyuBSr3/Ok2WDjGn37SWa39jgbKl6vxkke8Un1trK2QcjFFqH1GrBU0r7hTYOGfu3Pi 6GEw== X-Gm-Message-State: APjAAAXD84f2P0juzB6vGuVHnCQiPndSiS/kDnVFxCiLlYswEny2cm0n CFmcj8sqWSmyebfPWJi47hTLsSyS52j4Opmk9q4= X-Google-Smtp-Source: APXvYqwcoB5tpdLBXYfdBXkTPQXcG64dYhh9CnsAd5f0De8r/H1Bv854AVIZext596u/0zaw1hVN+9Ey+N4o1RQzeaY= X-Received: by 2002:ac2:43b7:: with SMTP id t23mr7915884lfl.110.1561845134492; Sat, 29 Jun 2019 14:52:14 -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> <000001d52e8f$a1f92b40$e5eb81c0$@jhdxr.com> In-Reply-To: Date: Sat, 29 Jun 2019 23:51:57 +0200 Message-ID: To: Benjamin Morel Cc: CHU Zhaowei , Stanislav Malyshev , PHP Internals Content-Type: multipart/alternative; boundary="0000000000006f8835058c7d680e" Subject: Re: [PHP-DEV] Memory leak in eval()'d code From: nikita.ppv@gmail.com (Nikita Popov) --0000000000006f8835058c7d680e Content-Type: text/plain; charset="UTF-8" On Sat, Jun 29, 2019 at 11:25 PM Benjamin Morel wrote: > > The problem here is that OP is *creating* many classes (the fact that > they are anonymous ultimately doesn't matter) by eval'ing code. That is > what causes the leak. > > I still don't understand why there is no leak when *not* using eval(), > though. > > Ben > Without eval you are creating many objects of the same anonymous class. With eval you are creating a single object each for many anonymous classes. In the first case there is only a single class, in the second there are as many classes as there are eval()s. That's the theory. In practice we have a long-standing bug with RTD key collisions -- this means that the names generated for anonymous classes (and closures for that matter) are not actually unique. For anonymous classes the current workaround is to reuse the existing class definition if an RTD key collision occurs. For your original code (and I should say that this is very specific to the code because it is susceptible to memory layout details) it happens that the RTD key for all those anonymous classes is the same, so in the end you end up with just one class definition also in the eval() case. The leaked memory is an allocated but unused class entry. We could plug that particular leak -- but I should emphasize that the current behavior is incorrect and once the key collision issue is resolved this will create a new class for each eval. Nikita --0000000000006f8835058c7d680e--