false, 'autoescape' => 'html']); $source = new Source('{{ "a"|upper }}{{ foo.bar }}{{ [1, 2]|join("-") }}{{ b ? "y" : "n" }}', 'index'); $ast = $env->parse($env->tokenize($source)); $refs = []; $collect = static function (Node $node) use (&$collect, &$refs) { $refs[] = \WeakReference::create($node); foreach ($node as $child) { $collect($child); } }; $collect($ast); $this->assertNotEmpty($refs); unset($ast, $collect); gc_collect_cycles(); $retained = 0; foreach ($refs as $ref) { if (null !== $ref->get()) { ++$retained; } } $this->assertSame(0, $retained, \sprintf('%d of %d AST nodes are still referenced after compilation.', $retained, \count($refs))); } }