开发者

PHP5: SplObjectStorage garbage collection

开发者 https://www.devze.com 2023-03-12 07:36 出处:网络
I\'m using a SplObjectStorage to keep information about managed objects. When my objects get destructed, I would like the SplObjectStorage to automatically cleanup the objects which have no external r

I'm using a SplObjectStorage to keep information about managed objects. When my objects get destructed, I would like the SplObjectStorage to automatically cleanup the objects which have no external references anymore.

I can see only two option开发者_如何学运维s for this right now:

  • having the managed object's destructor inform the storage to remove references to it; this is not acceptable as these objects should not be aware of the manager;
  • parsing debug_zval_dump() to get the reference count; not acceptable as well, IMHO too "hacky" for a serious application.

Any other ideas?


You can try to implement desired functionality with events. Each managed objects generates an event on destroy and the object manager is subscribed on this event so it will be able to remove a reference to object from the SplObjectStorage.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号