Hei*_*koG 2 iphone nsarray ios-simulator
任何人都可以为我清除这个吗?
我正在构建一个iPad应用程序,它有一个TableViewController,可以显示1000到2000个字符串之间的内容.我在单身人士中有那些NSStrings.
在Singleton的init方法中,我初始化一个包含所有数据的数组(不一定是最后的方法 - 只是一个快速的复制和粘贴测试)
我做了一个 self.someArray = [[NSArray alloc]initWithObjects:后跟大量的字符串,然后是零.
在模拟器中运行良好 - 但在应用程序启动时崩溃,iPad上的访问权限很差
如果我使用便捷方法[NSArray arrayWithObjects:- 它工作正常.
我查看了仪器,App的整体内存占用量仅为2.5 MB左右.
现在我不知道它为什么单向运行而不是另一条运行.
编辑:
#import "StaticValueContainer.h"`
static StaticValueContainer* instance = nil;
@implementation StaticValueContainer
@synthesize customerRatingKeys;
+(StaticValueContainer*)sharedInstance
{
if (instance == nil){
instance = [[StaticValueContainer alloc]init];
}
return instance;
}
-(id)init
{
if ( ( self = [super init] ))
{
[self initCustomerRatingKeys];
}
return self;
}
-(void)init customerRatingKeys
{
self.customerRatingKeys = [[NSArray alloc]initWithObjects:
@"string1",
....
@"string1245"
,nil
}
Run Code Online (Sandbox Code Playgroud)
正如我所说:它在设备上崩溃,self.customerRatingKeys = [[NSArray alloc]initWithObjects:
但与*self.customerRatingKeys = [[NSArray arrayWithObjects ...`
好吧,它们之间没有太大的区别:arrayWithObjects返回一个你不需要自己发布的自动释放的数组(除非你随后保留它),并initWithObjects返回一个数组,你必须释放它以避免内存泄漏.性能方面,它们之间没有区别.
我建议如果你使用initWithObjects但是没有使用错误的访问arrayWithObjects错误,你的代码中可能会出现某种内存管理错误.如果您发布代码本身,您可能会得到更准确的响应.
| 归档时间: |
|
| 查看次数: |
5683 次 |
| 最近记录: |