0
回答
NSArray的removeAllObjects
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

removeAllObjects会让element自动release.

下面是一个二维数组的用法。

	NSMutableArray* buddyList = [[NSMutableArray alloc] init];
	for (int i=0; i<5; i++) {
		[buddyList addObject:[[NSMutableArray alloc] init]];
	}
	for (int i=0; i<5; i++) {
		for (int j=0; j<6; j++) {
			NSString* str = [NSString stringWithFormat:@"%d%d", i, j];
			
			[[buddyList objectAtIndex:i] addObject:str];
		}
	}
//the 1th way to release
int i = 0;
	int j = 0;
	//1th way
	for (i=0; i<[buddyList count]; i++) {
	
		[[buddyList objectAtIndex:i] removeAllObjects];
	}
	[buddyList removeAllObjects];
	[buddyList release];
//the 2th way to release
	for (i=0; i<[buddyList count]; i++) {
		for (j=0; j<[[buddyList objectAtIndex:i] count]; j++) {
			[[[buddyList objectAtIndex:i] objectAtIndex:j] release];
		}
		
		[[buddyList objectAtIndex:i] release];
	}
	[buddyList release];
 


原文链接:http://blog.csdn.net/favormm/article/details/6076792
<无标签>
举报
长平狐
发帖于5年前 0回/1K+阅
顶部