gpt4 book ai didi

iphone - 我必须释放一个 NSLocalizedString 吗?

转载 作者:太空狗 更新时间:2023-10-30 03:59:50 27 4
gpt4 key购买 nike

问题很简单。我需要释放一个 NSLocalizedString 吗?例如:

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");

因为我这样做了:

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

但它打印的保留计数为 2。但是我读到 retainCount 属性不是很可靠。我应该释放它两次吗?

是的,我已经阅读了文档的内存管理规则和指南,但我在这里没有看到任何 NARC (NewAllocRetainCopy) 的指示。我还是个初学者,所以我真的不知道 NSLocalizedString 是如何生成字符串的。

谢谢!

EDIT1:我在 UIAlertView 中使用这个变量 我不知道当我使用它时 retainCount 是否增加了。根据 NSLog,即使不使用警报(在 if 内,并且如果跳过 if 则不使用),retainCount 仍然为 2。

最佳答案

不,你不能释放它。如果你检查 NSLocalizedString 是如何定义的,你会看到:

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

它通常是对返回自动释放字符串的 NSBundle 方法的调用

I use this variable in a UIAlertView I don't know if the retainCount is increased there when I use it. And even when the alert is not used (inside an if, and if the if is skipped it isn't used) the retainCount is still 2 according to NSLog.

是的,UIAlert 中的标签会保留它们的内容字符串,但您不必担心 - 它们会在销毁时释放它们。

关于iphone - 我必须释放一个 NSLocalizedString 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5165211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com