File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -418,7 +418,8 @@ private function invokeMicrotasks(): void
418418 [$ callback , $ args ] = $ this ->microtaskQueue ->dequeue ();
419419
420420 try {
421- $ callback (...$ args );
421+ // Clear $args to allow garbage collection
422+ $ callback (...$ args , ...($ args = []));
422423 } catch (\Throwable $ exception ) {
423424 $ this ->error ($ callback , $ exception );
424425 } finally {
Original file line number Diff line number Diff line change @@ -1387,6 +1387,24 @@ public function testMicrotaskExecutedImmediatelyAfterCallback(): void
13871387 });
13881388 }
13891389
1390+ public function testMicrotaskExecutionDoesNotKeepReferenceToArgs (): void
1391+ {
1392+ $ this ->expectOutputString ('123 ' );
1393+
1394+ $ this ->loop ->queue (function (object $ object ): void {
1395+ print 1 ;
1396+ unset($ object );
1397+ print 3 ;
1398+ }, new class () {
1399+ public function __destruct ()
1400+ {
1401+ print 2 ;
1402+ }
1403+ });
1404+
1405+ $ this ->loop ->run ();
1406+ }
1407+
13901408 public function testMicrotaskThrowingStillExecutesNextMicrotask (): void
13911409 {
13921410 $ exception = new \Exception ();
You can’t perform that action at this time.
0 commit comments