Skip to content
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

Observe gc events for the weakref? Would it work? #16

Open
Wes0617 opened this issue Jul 18, 2015 · 6 comments
Open

Observe gc events for the weakref? Would it work? #16

Wes0617 opened this issue Jul 18, 2015 · 6 comments
Assignees
Milestone

Comments

@Wes0617
Copy link

Wes0617 commented Jul 18, 2015

imagine the following:

$x = new WeakRef($obj);
$x->onLoss(function() use($map){
    echo "the object was garbage collected";
    $map->remove($weakref);
});
// or even...
$x->onBeforeLoss(function($object){
    echo "the object is about to be garbage collected";
    $map->save($object->serialize());
    // $weakref->acquire(); -> triggers "you aren't allowed to acquire a strong reference here"
});
@colder
Copy link
Owner

colder commented Aug 8, 2015

I think this would be good to have indeed. I need to reimplement most of weakref for php7 as the internals have changed (I'm not even sure weakref is possible anymore). Therefore it might be available only for php7 at first.

@colder colder self-assigned this Aug 8, 2015
@colder colder added this to the 0.3 - php7 milestone Aug 8, 2015
@Wes0617
Copy link
Author

Wes0617 commented Aug 8, 2015

it's ok php7 is the future and it's happening now! :D

@shoghicp
Copy link

👍 for php7 support and this feature, now I can remove all the hacks around this!

@pinepain
Copy link

@colder look how I implement notify callbacks functionality in my code in php_weak_referent_object_dtor_obj() at php_weak_reference.c:L126, the only drawback is if exception thrown in original dtor and in any of notifiers, all further notifiers will not be called.

@colder
Copy link
Owner

colder commented Jan 11, 2016

That makes sense, but don't you have to handle the case where the callback reads the reference and stores it elsewhere?

@pinepain
Copy link

I follow python's weakref.ref's notify appoach where notify callback get called with a weakref.ref object as a first arg after referent object destructed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants