RAGOpoR
RAGOpoR

Reputation: 8168

How to understand which property is suitable for NSDictionary eg. retain or assign?

now i using

@property (nonatomic, retain) NSDictionary *currentAttribute;

if i use copy or assign instead of retain is it more difference in memory performance?

Upvotes: 2

Views: 1548

Answers (1)

BoltClock
BoltClock

Reputation: 723598

Declaring it copy would mean you get an entirely new NSDictionary object for use with your class. If it's quite a large dictionary this can be a performance hit; not very noticeable, but significant anyway. By retaining it, you simply give your class its own pointer to the same NSDictionary instance.

Declaring it assign puts your application at risk of crashing in case the NSDictionary is autoreleased. If it ends up in the pool and gets deallocated because the pool reduced its retain count to 0, your class won't get to access it anymore, causing a crash.

Upvotes: 8

Related Questions