mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 12:55:26 +01:00
Fix FileAnalyzer memory leak
This commit is contained in:
parent
436ccae819
commit
6b7788b502
@ -306,6 +306,12 @@ class Context
|
||||
$this->self = $self;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$this->case_scope = null;
|
||||
$this->parent_context = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
@ -175,6 +175,8 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer implements StatementsSou
|
||||
$method_analyzer->analyze($context, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
$trait_file_analyzer->clearSourceBeforeDestruction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -120,12 +120,6 @@ class FileAnalyzer extends SourceAnalyzer implements StatementsSource
|
||||
$this->codebase = $project_analyzer->getCodebase();
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
/** @psalm-suppress PossiblyNullPropertyAssignmentValue */
|
||||
$this->source = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $preserve_analyzers
|
||||
*
|
||||
@ -629,4 +623,9 @@ class FileAnalyzer extends SourceAnalyzer implements StatementsSource
|
||||
{
|
||||
return $this->first_statement_offset;
|
||||
}
|
||||
|
||||
public function clearSourceBeforeDestruction()
|
||||
{
|
||||
$this->source = null;
|
||||
}
|
||||
}
|
||||
|
@ -1268,6 +1268,7 @@ class ProjectAnalyzer
|
||||
|
||||
$file_analyzer->class_analyzers_to_analyze = [];
|
||||
$file_analyzer->interface_analyzers_to_analyze = [];
|
||||
$file_analyzer->clearSourceBeforeDestruction();
|
||||
}
|
||||
|
||||
public function getFunctionLikeAnalyzer(string $method_id, string $file_path) : ?FunctionLikeAnalyzer
|
||||
|
@ -17,6 +17,11 @@ abstract class SourceAnalyzer implements StatementsSource
|
||||
*/
|
||||
protected $source;
|
||||
|
||||
public function __destruct() {
|
||||
/** @psalm-suppress PossiblyNullPropertyAssignmentValue */
|
||||
$this->source = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Aliases
|
||||
*/
|
||||
|
@ -260,6 +260,9 @@ class Analyzer
|
||||
$this->progress->debug('Analyzing ' . $file_analyzer->getFilePath() . "\n");
|
||||
|
||||
$file_analyzer->analyze(null);
|
||||
$file_analyzer->context = null;
|
||||
$file_analyzer->clearSourceBeforeDestruction();
|
||||
unset($file_analyzer);
|
||||
|
||||
return $this->getFileIssues($file_path);
|
||||
};
|
||||
|
@ -374,7 +374,7 @@ class StatementsProvider
|
||||
'comments', 'startLine', 'startFilePos', 'endFilePos',
|
||||
];
|
||||
|
||||
self::$parser = (new PhpParser\ParserFactory())->create(PhpParser\ParserFactory::PREFER_PHP7, self::$lexer);
|
||||
self::$parser = (new PhpParser\ParserFactory())->create(PhpParser\ParserFactory::ONLY_PHP7, self::$lexer);
|
||||
}
|
||||
|
||||
$used_cached_statements = false;
|
||||
@ -437,6 +437,11 @@ class StatementsProvider
|
||||
}
|
||||
}
|
||||
|
||||
/** @psalm-suppress NoInterfaceProperties */
|
||||
unset(self::$parser->errorHander);
|
||||
|
||||
$error_handler->clearErrors();
|
||||
|
||||
$resolving_traverser = new PhpParser\NodeTraverser;
|
||||
$name_resolver = new \Psalm\Internal\Visitor\SimpleNameResolver(
|
||||
$error_handler,
|
||||
|
Loading…
Reference in New Issue
Block a user