bug #11454 [Validator] Fixed memory leak in ValidatorBuilder (webmozart)
This PR was merged into the 2.5 branch. Discussion ---------- [Validator] Fixed memory leak in ValidatorBuilder | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11236 | License | MIT | Doc PR | - In23534ca6ab
, the following code was introduced in `ValidatorBuilder::getValidator()`: ```php AnnotationRegistry::registerLoader(function ($class) { if (0 === strpos($class, __NAMESPACE__.'\\Constraints\\')) { $file = str_replace(__NAMESPACE__.'\\Constraints\\', __DIR__.'/Constraints/', $class).'.php'; if (is_file($file)) { require_once $file; return true; } } return false; }); ``` `AnnotationRegistry::registerLoader()` stores all loaders in a global array. Every time that `getValidator()` is called, a new closure is put onto the loader stack, referencing `$this` (i.e. the ValidatorBuilder) and consequently preventing the ValidatorBuilder (and its references) from being garbage-collected. The call to `registerLoader()` did not exist in 2.4 and I can't find a reason why it should be there. All tests are green without that code. I suppose I used it for debugging and then forgot to remove it again, so I'm removing it here. Commits -------283387a
[Validator] Fixed memory leak in ValidatorBuilder
This commit is contained in:
commit
2f7b702e3b
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\Validator;
|
namespace Symfony\Component\Validator;
|
||||||
|
|
||||||
use Doctrine\Common\Annotations\AnnotationReader;
|
use Doctrine\Common\Annotations\AnnotationReader;
|
||||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
|
||||||
use Doctrine\Common\Annotations\CachedReader;
|
use Doctrine\Common\Annotations\CachedReader;
|
||||||
use Doctrine\Common\Annotations\Reader;
|
use Doctrine\Common\Annotations\Reader;
|
||||||
use Doctrine\Common\Cache\ArrayCache;
|
use Doctrine\Common\Cache\ArrayCache;
|
||||||
@ -367,20 +366,6 @@ class ValidatorBuilder implements ValidatorBuilderInterface
|
|||||||
|
|
||||||
if ($this->annotationReader) {
|
if ($this->annotationReader) {
|
||||||
$loaders[] = new AnnotationLoader($this->annotationReader);
|
$loaders[] = new AnnotationLoader($this->annotationReader);
|
||||||
|
|
||||||
AnnotationRegistry::registerLoader(function ($class) {
|
|
||||||
if (0 === strpos($class, __NAMESPACE__.'\\Constraints\\')) {
|
|
||||||
$file = str_replace(__NAMESPACE__.'\\Constraints\\', __DIR__.'/Constraints/', $class).'.php';
|
|
||||||
|
|
||||||
if (is_file($file)) {
|
|
||||||
require_once $file;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$loader = null;
|
$loader = null;
|
||||||
|
Reference in New Issue
Block a user