【发布时间】:2011-03-05 00:52:50
【问题描述】:
我已经使用这段代码几天了,试图确定一些内存泄漏的原因。 “for 循环”之后的几乎每一行都会在泄漏性能工具中生成内存泄漏百分比。
我一直在尝试各种排列以使其发挥作用。
这是我现在正在运行的代码,试图深入了解它:
-(void)populateArrays
{
NSArray *arrTempSorted;
[arrContacts removeAllObjects];
[arrZzoneContacts removeAllObjects];
[arrNormalContacts removeAllObjects];
for( int i = 0 ; i < 200 ; i++ )
{
[arrZzoneContacts addObject:[[[NSArray alloc] initWithObjects: [NSNumber numberWithInt:1], @"Composite Name", @"YES", @"first name", @"last name", @"first", nil] autorelease]];
[arrNormalContacts insertObject:[[[NSArray alloc] initWithObjects: [NSNumber numberWithInt:1], @"Composite Name", @"YES", @"first name", @"last name", @"first", nil] autorelease] atIndex:[arrNormalContacts count]];
[arrContacts addObject:[[[NSArray alloc] initWithObjects: [NSNumber numberWithInt:1], @"Composite Name", @"YES", @"first name", @"last name", @"first", nil] autorelease]];
}
arrTempSorted = [arrContacts sortedArrayUsingFunction:order context:NULL];
arrContacts = [arrTempSorted mutableCopy];
arrTempSorted = [arrZzoneContacts sortedArrayUsingFunction:order context:NULL];
arrZzoneContacts = [arrTempSorted mutableCopy];
arrTempSorted = [arrNormalContacts sortedArrayUsingFunction:order context:NULL];
arrNormalContacts = [arrTempSorted mutableCopy];
//[arrTempSorted release];
}
数组和函数在 appDelegate.h 文件中。数组的初始化如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//Global variables
arrContacts = [[NSMutableArray alloc] init];
arrZzoneContacts = [[NSMutableArray alloc] init];
arrNormalContacts = [[NSMutableArray alloc] init];
// Override point for customization after application launch.
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
我尝试过在 didFinishLaunchingWithOptions 中声明一个数组然后将其分配给 arrContacts(例如)然后释放它的方法,但是当我们使用 populateArrays 方法时出现“错误访问”错误。
任何见解将不胜感激,如果我可以提供更多详细信息,请告诉我
【问题讨论】:
标签: iphone objective-c nsmutablearray nsarray