Last active
October 22, 2021 18:48
-
-
Save DarkGhostHunter/bcb20b16df8b07215defeaa57e61aa3f to your computer and use it in GitHub Desktop.
Creates the application 1,000 times
This file contains 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 | |
namespace Tests\Feature; | |
use Tests\TestCase; | |
class ExampleTest extends TestCase | |
{ | |
public function test_leaks_memory_on_1000_iterations() | |
{ | |
// Remove the existing application instance. | |
$this->app->flush(); | |
$this->app = null; | |
// Let's create a fully booted application instance 1,000 times. | |
for($i = 1; $i < 1000; ++$i) { | |
$this->createApplication()->flush(); | |
// Each 50 times, report the MB used by the PHP process by dumping it. | |
if (! $i % 50) { | |
dump('Using ' . ((int) (memory_get_usage(true) / (1024 * 1024))) . 'MB as ' . $i . ' iterations.'); | |
} | |
} | |
$this->app = $this->createApplication(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment