iphone sdk的保留计数问题
我面临的内存泄漏问题如下:iphone sdk的保留计数问题,iphone,memory-management,memory-leaks,Iphone,Memory Management,Memory Leaks,我面临的内存泄漏问题如下: 我正在B类中分配A类对象。//A类对象的保留计数变为1 我正在将对象放置在nsmutablearray中。//类对象的保留计数变为2 在另一个C类中,我获取这个nsmutablearray,获取所有元素,如 for(NSInteger f=0; f< [appDelegate.category_type count]; f++) { [category_type addObject:[appDelegate.category_type objectAtIndex
for(NSInteger f=0; f< [appDelegate.category_type count]; f++)
{
[category_type addObject:[appDelegate.category_type objectAtIndex:f]];
}
//a的保留计数变为2[分配+保留计数为1的提取对象]提前准备好 我正在B类中分配A类对象。//A类对象的保留计数变为1 我正在将对象放置在nsmutablearray中。//类对象的保留计数变为2 在另一个C类中,我获取这个nsmutablearray,在本地nsmutablearray中获取该数组中的所有元素,//RU如何获取??? 释放类B的第一个数组。//本地数组中类A对象的保留计数变为1 现在在这个类C中,我创建了一个类A的对象,并获取本地nsmutable数组中的元素//本地数组中新类A对象的保留计数变为2[分配+保留计数为1的已获取对象] 请详细说明这一点,以便容易理解问题
for(NSInteger f=0; f< [appDelegate.category_type count]; f++)
{
[category_type addObject:[appDelegate.category_type objectAtIndex:f]];
}
NSLog(@"appDelegate.category_type count => %d and category_type count => %d",[appDelegate.category_type count],[category_type count]);
for(NSInteger f=0;f<[appDelegate.category_type count];f++)
{
[category_type addObject:[appDelegate.category_type objectAtIndex:f];
}
NSLog(@“appDelegate.category_type count=>%d和category_type count=>%d”,[appDelegate.category_type count],[category_type count]);
试用已编辑的代码并查看两个数组的计数。两者都将打印相同的计数,表示两者都有对象即使在释放appDelegate.category\u类型数组之后,对象的保留计数也将是2而不是1。我试图理解您的问题,这就是我认为您所说的: 一, 二, 三, 你需要告诉我们更多关于你在哪里释放对象的信息——在(3)中你说你正在“释放B类的第一个数组”——你能告诉我们代码吗 看起来您保留了该对象3次,但没有发布任何代码来显示它被释放
我认为你需要做更多类似的事情: 1和2。(B类) 三,。(丙类) 四,
for(NSInteger f=0; f< [appDelegate.category_type count]; f++)
{
[category_type addObject:[appDelegate.category_type objectAtIndex:f]];
}
NSLog(@"appDelegate.category_type count => %d and category_type count => %d",[appDelegate.category_type count],[category_type count]);
A *a = [[A alloc] init];
[category_type addObject:a];
for(NSInteger f=0; f< [appDelegate.category_type count]; f++)
[category_type addObject:[appDelegate.category_type objectAtIndex:f]];
A *a = [category_type objectAtIndex:i];
A *a = [[[A alloc] init] autorelease];
[category_type release];
category_type = [NSMutableArray alloc] init];
[category_type addObject:a];
[category_type release];
category_type = [[NSArray arrayWithArray:appDelegate.category_type] retain];
A *a = [category_type objectAtIndex:i];