-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow GC of arguments during microtask execution #60
Conversation
@@ -418,7 +418,8 @@ private function invokeMicrotasks(): void | |||
[$callback, $args] = $this->microtaskQueue->dequeue(); | |||
|
|||
try { | |||
$callback(...$args); | |||
// Clear $args to allow garbage collection | |||
$callback(...$args, ...($args = [])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So how does this work? You first pass all the elements of the $args
array into the argument list for $callback
, and then you overwrite $args
with an empty array and also "push" that to the same argument list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it overwrites the $args
array (and pushes zero arguments to the argument list) after pushing the original arguments and before invoking the callback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Near trick, it's a tad confusing when you first read the line tbh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better documentation what happens here would be good especially for people like me that doesn't see what's happening at the first glance and why it's needed.
... Though, it might be that this doesn't work here, as cufa() stores its own CoW copy of its args until its end... |
@Nevay Thanks for finding this and for the creative solution. Seems we rarely pass arguments, let alone instantiating objects in the argument list, so this hadn't come up. We appreciate the real-world testing to find these cases! |
No description provided.