|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-11-04 17:14 UTC] uramihsayibok at gmail dot com
[2012-10-24 10:13 UTC] jille at hexon dot cx
[2012-10-25 01:17 UTC] aharvey@php.net
-Status: Open
+Status: Not a bug
[2012-10-25 01:17 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 29 17:00:01 2025 UTC |
Description: ------------ I encountered a similar issue to #25335 where custom error handler + exceptions leaks memory but only when try-catch block is in a function and looped through directly. I imagine there's some scope/GC issues here, and whether this is actual bug or limitation of PHP. Test script: --------------- <? set_error_handler(function($errno, $errstr, $errfile, $errline){ throw new Exception($errstr); }); function leak() { while (true) { try { // throw new Exception(); //it doesn't leak if it's thrown directly 1 / 0; //leaks } catch (Exception $e) {} echo memory_get_usage(), PHP_EOL; } } leak(); /* it doesn't leak if it's outside of the function */ while (true) { try { 1 / 0; } catch (Exception $e) { } echo memory_get_usage(), PHP_EOL; } /* it doesn't leak if try-catch block is in a separate function */ function foo() { $try = function(){ try {1 / 0;} catch (Exception $e) {} }; while (true) { $try(); echo memory_get_usage(), PHP_EOL; } } foo(); Expected result: ---------------- 637512 637512 637512 637512 637512 637512 ... Actual result: -------------- 639432 644272 649080 653896 658704 663512 668320 ...