【原】NSMutableArray的alloc、init方法与array的区别疑问
在项目中的这个函数里面,[NSMutableArray array]与[[NSMutableArray alloc] init];有着较明显的区别
同样是建立一个NSMutableArray临时变量,为什么前者可以,后者在多次调用clearLastLine函数时会出错呢?
亟待解决!在TryIt.proj->FingerPaintView里面
- (void)clearLastLine {
NSMutableArray *lastLine = [NSMutableArray array];
if ([mDrawLines count] >= 1)
{
lastLine = [mDrawLines objectAtIndex:[mDrawLines count]-1];
[mRemovedLines addObject:lastLine];
[mDrawLines removeLastObject];
NSLog(@"%s:removed lines:%@",__FUNCTION__,mRemovedLines);
mCurrentLine = nil;
[self setNeedsDisplay];//系统会调用drawRect绘图
}
}
/////////////////
- (void)clearLastLine {
NSMutableArray *lastLine = [[NSMutableArray alloc] init];
if ([mDrawLines count] >= 1)
{
lastLine = [mDrawLines objectAtIndex:[mDrawLines count]-1];
[mRemovedLines addObject:lastLine];
[lastLine release];
[mDrawLines removeLastObject];
NSLog(@"%s:removed lines:%@",__FUNCTION__,mRemovedLines);
mCurrentLine = nil;
[self setNeedsDisplay];//系统会调用drawRect绘图
}
}