作者:雨的到来2009 | 来源:互联网 | 2023-05-17 13:29
IveusinganNSHashTabletostoreweakreferencestoobjects.Whenanobjectinthehashtableisd
I've using an NSHashTable to store weak references to objects. When an object in the hash table is deallocated and the reference is zeroed within the hash table, the pointer to nil still resides in the hash table, correct? So over time, if objects that are deallocated aren't directly removed from the hash table, the hash table will continue to grow in size? Right now, there is no easy way to send a notification to the object controlling the hash table that one of the hash tables elements have been removed (it's a game where feedback calls mean communication between objects is very indirect, and preferably stays that way). Should I iterate over the hash table periodically to remove nil references?
我使用NSHashTable来存储对象的弱引用。当哈希表中的一个对象被释放并且引用在哈希表中归零时,指向nil的指针仍然驻留在哈希表中,对吗?所以随着时间的推移,如果释放的对象没有直接从哈希表中删除,哈希表的大小会继续增加?现在,没有一种简单的方法可以向控制哈希表的对象发送一个通知,该对象已经删除了哈希表的一个元素(在这个游戏中,反馈调用意味着对象之间的通信非常间接,最好保持这种方式)。我应该定期遍历哈希表以删除nil引用吗?
2 个解决方案