Skip to content

Instantly share code, notes, and snippets.

@hanabokuro
Created July 26, 2016 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanabokuro/cc7f77381945d26e777cc0a3c94e984a to your computer and use it in GitHub Desktop.
Save hanabokuro/cc7f77381945d26e777cc0a3c94e984a to your computer and use it in GitHub Desktop.
memory leak
<?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