Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:17726 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48883 invoked by uid 1010); 9 Aug 2005 19:40:17 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 48868 invoked from network); 9 Aug 2005 19:40:17 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2005 19:40:17 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:48887] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id BB/3C-04646-0A609F24 for ; Tue, 09 Aug 2005 15:40:17 -0400 Received: (qmail 6987 invoked from network); 9 Aug 2005 19:40:13 -0000 Received: from localhost (HELO ANDI-NOTEBOOK.zend.com) (127.0.0.1) by localhost with SMTP; 9 Aug 2005 19:40:13 -0000 Message-ID: <5.1.0.14.2.20050809123954.03491eb0@localhost> X-Sender: andi@localhost X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Tue, 09 Aug 2005 12:40:09 -0700 To: "Ron Korving" ,internals@lists.php.net In-Reply-To: <1B.EF.04646.95CC8F24@pb1.pair.com> References: <21.AF.04646.20AC8F24@pb1.pair.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] Re: drastic memory consumption with a sequence of exceptions From: andi@zend.com (Andi Gutmans) Can you send a complete script which also passes $data that reproduces the problem? Thanks. At 05:27 PM 8/9/2005 +0200, Ron Korving wrote: >The problem occurs in this particular situation: > >public function process($data) >{ > $largeResultSet = $this->xmlParser->parseString($data); > > foreach ($largeResultSet as &$item) > { > throw new Exception("error"); > } >} > >It only happens if the exception is thrown from within the foreach(). It >seems the $largeResultSet is not freed in this case. Using the foreach by >reference or not (&$item or $item) does not make a difference. > >Ron > > >""Ron Korving"" schreef in bericht >news:21.AF.04646.20AC8F24@pb1.pair.com... > > It is very likely that this has something to do with DOM. It's a huge >piece > > of code though, making it hard to test where the problem really lies. > > > > ""Ron Korving"" schreef in bericht > > news:BD.4F.04646.AA6C8F24@pb1.pair.com... > > > I've noticed that in a script of mine, memory consumption can explode > > quite > > > drastically when Exceptions are thrown, opposed to very normal memory > > > consumption when exceptions are not thrown. > > > > > > This is the idea: > > > > > > > > class Obj > > > { > > > function process($i) > > > { > > > // do a lot of stuff, occupy a lot of memory within the scope of >this > > > function > > > throw new Exception("error"); > > > } > > > } > > > > > > $obj = new Obj(); > > > $errors = array(); > > > > > > for ($i=0; $i < 60; $i++) > > > { > > > try > > > { > > > $obj->process(); > > > } > > > catch (Exception $e) > > > { > > > $errors[] = $e->getMessage(); > > > } > > > } > > > ?> > > > > > > When exceptions are not thrown, memory consumption is normal. The >method's > > > local vars are freed and not much more memory is used in the 50th pass > > > compared to the 1st. But when exceptions are thrown, memory consumption > > > increases quite a bit every pass. In the end (within the 60 passes of my > > > loop) over 8 MB's are used. > > > > > > Of course, I can unset a lot of data before throwing exceptions to free >up > > > memory and the problem will be solved. But it would be nicer if the > > cleanup > > > would happen as an exception is thrown. > > > > > > Can this be considered a bug or is this behavior known and accepted? > > > > > > Ron > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: http://www.php.net/unsub.php