I have the following code:
NSDictionary *dict = @{ @"myKey" : @"myValue" };
Should I release dict
using release
or autorelease
?
Or I do not own the object, so I should not release it myself?
Note: I use manual reference counting (ARC is disabled).
No, you must not release a NSDictionary
created with the literal syntax. The Clang documentation tells that dictionary literal expressions expand to +[NSDictionary dictionaryWithObjects:forKeys:count:]
, so you do not own the object.
No Objective-C literal expands to an expression creating an owning reference.
Even if you have ARC disabled (which you should have it enabled), you do not need to release it because you do not own the object. You only own the object when you created it through alloc
or new
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With