开发者

Memory retention of an NSArray of NSDictionaries

I want an ivar that is an ordered list of dictionaries. If I create an @property for this NSArray, set to retain and then fill it with NSDictionary objects, can I "saf开发者_运维百科ely" assume these dictionaries are also retained as part of the ivar, or do I need to separately retain these objects?


Yes, the collection classes will automatically retain the things you put in them. So if you put things in a dictionary and maintain a reference to the dictionary, you can safely use its contents; and if you store this dictionary in a property you can still safely use it. See this page for more information:

  • They maintain strong references to their contents.


NSArray retains objects when they're added, and releases them when they're removed or the array is deallocated. Keep this in mind, it's this concept of "ownership" that retain/release memory management is built upon.

With an NSArray of object references, do I explicitly release all objects in the array or just the array itself?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜