文字NSString是自动释放的还是需要释放的? [英] Is a literal NSString autoreleased or does it need to be released?
本文介绍了文字NSString是自动释放的还是需要释放的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下符号创建字符串时:
When creating a string using the following notation:
NSString *foo = @"Bar";
是否需要释放foo
?还是foo
在这种情况下会自动发布?
Does one need to release foo
? Or is foo
autoreleased in this case?
推荐答案
编译器分配的字符串(格式为@"STRING")是常量,因此-retain,-release和-autorelease消息将被忽略.在这种情况下,您不必释放或自动释放foo(但这不会造成伤害).
Compiler allocated strings (of the format @"STRING") are constant, and so -retain, -release, and -autorelease messages to them are ignored. You don't have to release or autorelease foo in this case (but it won't hurt).
这篇关于文字NSString是自动释放的还是需要释放的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文