NSMapTable and NSMutableDictionary differences

前端 未结 4 835
广开言路
广开言路 2020-12-09 19:17

Is an NSMapTable the same as an NSMutableDictionary except for allowing keys to be pointers?

Does it differ in memory management?

4条回答
  •  醉梦人生
    2020-12-09 19:46

    Be aware that NSMapTable sometimes not deallocates keys and objects if weak-weak, weak-strong or strong-weak bindings are used http://cocoamine.net/blog/2013/12/13/nsmaptable-and-zeroing-weak-references/.

    Also in NSMapTable.h you can find that 'entries are not necessarily purged right away when the weak key is reclaimed' :

    + (id)weakToStrongObjectsMapTable NS_AVAILABLE(10_8, 6_0); 
    // entries are not necessarily purged right away when the weak key is reclaimed
    + (id)weakToWeakObjectsMapTable NS_AVAILABLE(10_8, 6_0); 
    // entries are not necessarily purged right away when the weak key or object is reclaimed
    

提交回复
热议问题