Created
July 26, 2016 04:11
-
-
Save hanabokuro/cc7f77381945d26e777cc0a3c94e984a to your computer and use it in GitHub Desktop.
memory leak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Foo { | |
static function throw_exception_maybe() | |
{ | |
if(rand(0, 10) < 3) { | |
throw new Exception(); | |
} | |
return 'xxx'; | |
} | |
} | |
while(true) { | |
gc_collect_cycles(); | |
for($i = 0;$i < 10000;$i ++ ) { | |
try { | |
$x = [ | |
'no_memory_leak_if_comment_out_this_line' => 1, | |
'xxx' => Foo::throw_exception_maybe(), | |
]; | |
} catch (Exception $e) { | |
} | |
} | |
printf("%5.3fM\n", memory_get_usage() / (1000 * 1000)); // byte => Mbyte | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment