Should I release an NSLocalizedString?

The question is simple. Do I need to release an NSLocalizedString? For instance:

NSString *internetMessageTitle = NSLocalizedString( @"You are currently not connected to a internet network" @"Title of the message that tells the user there is no internet network"); 

Because I did this:

 NSLog(@"Retain count of InternetMessageTitle is: %d", [internetMessage retainCount]); 

But it prints save counter 2. However, I read that the saveCount attribute is not very reliable. Should I let him go twice?

And yes, I read the memory management rules and documentation guide, but I don't see any NARC (NewAllocRetainCopy) guidelines here. I'm still a newbie, so I really don't know how NSLocalizedString creates strings.

Thanks!

EDIT1: I use this variable in UIAlertView. I do not know if the keepCount value increases there when I use it. And even when the warning is not used (inside if, and if omitted, then it is not used). SaveCount is still 2 according to NSLog.

+4
source share
3 answers

No, you should not let him go. If you check how NSLocalizedString is determined, you will see:

 #define NSLocalizedString(key, comment) \ [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] 

This is usually a call to the NSBundle method, which returns a string with auto-implementation

I use this variable in UIAlertView I don’t know if keepCount is when I use it. And also even if the warning is not used (inside a if, and if if it is skipped it is not used) keepCount is still 2 according to NSLog.

Yes, tags in UIAlert retain their content lines, but you should not worry about that - they will release them when they are destroyed.

+8
source

As you say, there is no NARC - so you already know that the answer is no.

And what did you read about saving the account? Take it easy. Never look at a save account as useful information. Never look at everything.

And FFS doesn't do something crazy like calling release for an object several times just because you think it has a save account> 1. This stuff is absolutely guaranteed to ruin you.

+1
source

Cocoa memory management rules are very simple. There is only one of the consequences: all calls to alloc / new * / * copy must be balanced by a call to auto-release. You do not call a method or function named "alloc", starting with "new" or containing a "copy", so you should not let go.

It is even simpler than following the rules of memory to use properties (an object or class ) whenever possible.

0
source

Source: https://habr.com/ru/post/1341945/


All Articles