8000 Add gc_mem_caches() call for PHP7 after itoken_get_all() as new memor… · symfony/symfony@e555aad · GitHub
[go: up one dir, main page]

Skip to content

Commit e555aad

Browse files
Peter Wardnicolas-grekas
Peter Ward
authored andcommitted
Add gc_mem_caches() call for PHP7 after itoken_get_all() as new memory manager will not release small buckets to OS automatically
1 parent d1f72d8 commit e555aad

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Translation/PhpExtractor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public function extract($directory, MessageCatalogue $catalog)
6161
$files = $finder->files()->name('*.php')->in($directory);
6262
foreach ($files as $file) {
6363
$this->parseTokens(token_get_all(file_get_contents($file)), $catalog);
64+
65+
if (PHP_VERSION_ID >= 70000) {
66+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
67+
gc_mem_caches();
68+
}
6469
}
6570
}
6671

src/Symfony/Component/ClassLoader/ClassCollectionLoader.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,15 @@ public static function fixNamespaceDeclarations($source)
193193
$rawChunk .= "}\n";
194194
}
195195

196-
return $output.self::compressCode($rawChunk);
196+
$output .= self::compressCode($rawChunk);
197+
198+
if (PHP_VERSION_ID >= 70000) {
199+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
200+
unset($tokens, $rawChunk);
201+
gc_mem_caches();
202+
}
203+
204+
return $output;
197205
}
198206

199207
/**

src/Symfony/Component/ClassLoader/ClassMapGenerator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public static function createMap($dir)
7272

7373
$classes = self::findClasses($path);
7474

75+
if (PHP_VERSION_ID >= 70000) {
76+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
77+
gc_mem_caches();
78+
}
79+
7580
foreach ($classes as $class) {
7681
$map[$class] = $path;
7782
}

src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,12 @@ public static function stripComments($source)
733733

734734
$output .= $rawChunk;
735735

736+
if (PHP_VERSION_ID >= 70000) {
737+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
738+
unset($tokens, $rawChunk);
739+
gc_mem_caches();
740+
}
741+
736742
return $output;
737743
}
738744

src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ public function load($file, $type = null)
6464
$collection->addResource(new FileResource($path));
6565
$collection->addCollection($this->loader->load($class, $type));
6666
}
67+
if (PHP_VERSION_ID >= 70000) {
68+
// PHP 7 memory manager will not release after token_get_all(), see https://bugs.php.net/70098
69+
gc_mem_caches();
70+
}
6771

6872
return $collection;
6973
}

0 commit comments

Comments
 (0)
0