Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:106094 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 51221 invoked from network); 28 Jun 2019 20:31:54 -0000 Received: from unknown (HELO mail.experimentalworks.net) (84.19.169.162) by pb1.pair.com with SMTP; 28 Jun 2019 20:31:54 -0000 Received: from [192.168.2.46] (ppp-188-174-56-116.dynamic.mnet-online.de [188.174.56.116]) by mail.experimentalworks.net (Postfix) with ESMTPSA id DB95B4FDE5; Fri, 28 Jun 2019 19:48:50 +0200 (CEST) Date: Fri, 28 Jun 2019 19:48:48 +0200 User-Agent: K-9 Mail for Android In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable To: Benjamin Morel CC: PHP Internals Message-ID: Subject: Re: [PHP-DEV] Memory leak in eval()'d code From: johannes@schlueters.de (=?ISO-8859-1?Q?Johannes_Schl=FCter?=) On June 28, 2019 6:49:49 PM GMT+02:00, Benjamin Morel wrote: > >> or unload the class once >> it's not needed anymore (which is hard to detect with reflection and >> other mechanisms which aren't bound to an instance's zval and also >not >> cheap) > >AFAIK, unloading a class is not possible from userland, I guess you're >talking about detecting this in PHP itself? Correct=2E >Anyway, that's an edge case, I found a workaround which is to keep a >cache >of freshly created objects, indexed by interface name(s)=2E >Anytime I request a combination of types that's already been handled in >the >past, I return a clone of the cached object=2E > >Even though the possible combinations of types are huge and impossible >to >predict in advance, there are never more than a handful of such >combinations used in a single document, and I'd be surprised if there >are >actually that many combinations actually used in the wild=2E So this >should >hardly be a problem=2E This is going to be off-topic for his list: you could rethink your approac= h=2E Maybe you can generate the classes only on demand (if you can derive t= he information from a class name an evil way is `function __autoload($class= name) { /* figure out what is needed */ eval("class $classname { =2E=2E=2E}= ")}` =2E=2E=2E absolutely evil, but hides the machinery) or you could rethi= nk whether you really need distinct classes or whether a single type with a= ccessor routines (either some custom or __call/__set/__get) isn't sufficien= t=2E Or something else =2E=2E=2E johannes