-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Implement acyclic object tracking #17130
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -705,6 +705,8 @@ void zend_register_closure_ce(void) /* {{{ */ | |
zend_ce_closure = register_class_Closure(); | ||
zend_ce_closure->create_object = zend_closure_new; | ||
zend_ce_closure->default_object_handlers = &closure_handlers; | ||
/* FIXME: Potentially infer ZEND_ACC_MAY_BE_CYCLIC during construction of | ||
* closure? static closures not binding by references can't be cyclic. */ | ||
Comment on lines
+708
to
+709
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 this looks worth it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm afraid my comment was incorrect. class Test {
public \Closure $c;
}
$test = new Test();
$c = static function () use ($test) {}; // acyclic
$test->c = $c; // now it's cyclic
unset($test);
gc_collect_cycles();
unset($c); // leaks This is only ok if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth mentioning: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, your test case doesn't show any dynamic property usage @iluuu1994, wouldn't that still be an issue in non-readonly cases even in PHP 9.0? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was referring to:
I.e. it's safe to assume
Yes, but it's not a priority since it's a rare case and unlikely to make a big difference. |
||
|
||
memcpy(&closure_handlers, &std_object_handlers, sizeof(zend_object_handlers)); | ||
closure_handlers.free_obj = zend_closure_free_storage; | ||
|
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.
We should also mark classes with custom
get_properties
handler as potentially cyclic, as this is called byzend_std_get_gc
.Otherwise this looks right to me, as objects with std
get_gc
andget_properties
can not expose anything other than standard properties to the GC.Lazy objects need to take care of updating
GC_NOT_COLLECTABLE
: RemoveGC_NOT_COLLECTABLE
inzend_object_make_lazy()
when the initializer is cyclic or may have a ref to the object itself, and add it again inzend_lazy_object_init()
.