Skip to content

Instantly share code, notes, and snippets.

@DarkGhostHunter
Last active October 22, 2021 18:48
Show Gist options
  • Save DarkGhostHunter/bcb20b16df8b07215defeaa57e61aa3f to your computer and use it in GitHub Desktop.
Save DarkGhostHunter/bcb20b16df8b07215defeaa57e61aa3f to your computer and use it in GitHub Desktop.
Creates the application 1,000 times
<?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