Re: Re: drastic memory consumption with a sequence of exceptions
| From: | Andi Gutmans | Date: | Tue, 09 Aug 2005 19:40:09 +0000 |
| Subject: | Re: Re: drastic memory consumption with a sequence of exceptions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-17726@lists.php.net to get a copy of this message | ||
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"" <r.korving@xit.nl> 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"" <r.korving@xit.nl> schreef in bericht news:BD.4F.04646.AA6C8F24@pb1.pair.com...I've noticed that in a script of mine, memory consumption can explodequitedrastically when Exceptions are thrown, opposed to very normal memory consumption when exceptions are not thrown. This is the idea: <? class Obj { function process($i) {this// do a lot of stuff, occupy a lot of memory within the scope offunctionmethod'sthrow 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. Thelocal 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 freeupmemory and the problem will be solved. But it would be nicer if thecleanupwould 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