Ios4 Iphone应用程序性能正在放缓,内存是否泄漏?
我有一个IPhone绘图应用程序,当我使用spray-can工具时,它会变慢。但是,当我通过运行带有泄漏的应用程序来检查泄漏时,不会显示任何泄漏。所有其他工具都运行良好,可以帮助我解决此问题 我的喷雾罐工具类别代码如下:Ios4 Iphone应用程序性能正在放缓,内存是否泄漏?,ios4,drawing,bezier,nsbezierpath,Ios4,Drawing,Bezier,Nsbezierpath,我有一个IPhone绘图应用程序,当我使用spray-can工具时,它会变慢。但是,当我通过运行带有泄漏的应用程序来检查泄漏时,不会显示任何泄漏。所有其他工具都运行良好,可以帮助我解决此问题 我的喷雾罐工具类别代码如下: - init { if ((self = [super init])) { trackingTouches = [[NSMutableArray array] retain]; startPoints = [[NS
- init {
if ((self = [super init]))
{
trackingTouches = [[NSMutableArray array] retain];
startPoints = [[NSMutableArray array] retain];
paths = [[NSMutableArray array] retain];
}
return self;
}
- (void)activate { } - (void)deactivate {
[trackingTouches removeAllObjects];
[startPoints removeAllObjects];
[paths removeAllObjects];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// UIView *touchedView = [delegate viewForUseWithTool:self];
UITouch *theTouch = [touches anyObject];
UIView *touchedView = [delegate viewForUseWithTool:self];
endPoint = [theTouch locationInView:touchedView];
for (UITouch *touch in [event allTouches]) {
// CGFloat lineWidth=10;
// remember the touch, and its original start point, for future
[trackingTouches addObject:touch];
CGPoint location = [touch locationInView:touchedView];
[startPoints addObject:[NSValue valueWithCGPoint:location]];
UIBezierPath *path = [UIBezierPath bezierPath];
path.lineCapStyle = kCGLineCapRound;
[path moveToPoint:location];
[path setLineWidth:delegate.strokeWidth];
[path addLineToPoint:location];
[paths addObject:path];
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[self deactivate];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// UITouch *theTouch = [touches anyObject];
// UIView *touchedView = [delegate viewForUseWithTool:self];
//endPoint = [theTouch locationInView:touchedView];
for (UITouch *touch in [event allTouches])
{ // make a line from the start point to the current point
NSUInteger touchIndex = [trackingTouches indexOfObject:touch];
// only if we actually remember the start of this touch...
if (touchIndex != NSNotFound) {
UIBezierPath *path = [paths objectAtIndex:touchIndex];
PathDrawingInfo *info = [PathDrawingInfo pathDrawingInfoWithPath:path fillColor:[UIColor clearColor] strokeColor:delegate.strokeColor];
[delegate addDrawable:info];
[trackingTouches removeObjectAtIndex:touchIndex];
[startPoints removeObjectAtIndex:touchIndex];
[paths removeObjectAtIndex:touchIndex];
}
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// UIView *touchedView = [delegate viewForUseWithTool:self];
UITouch *theTouch = [touches anyObject];
UIView *touchedView = [delegate viewForUseWithTool:self];
currentpoint = [theTouch locationInView:touchedView];
//currentpoint.y -=20;
//[self drawCircle];
for (UITouch *touch in [event allTouches]) {
CGFloat lineWidth=10;
// make a line from the start point to the current point
NSUInteger touchIndex = [trackingTouches indexOfObject:touch];
UIBezierPath *path = [UIBezierPath bezierPath];
if (touchIndex != NSNotFound) {
// CGPoint location = [touch locationInView:touchedView];
UIBezierPath *path = [paths objectAtIndex:touchIndex]; UIBezierPath *circle = [UIBezierPath bezierPathWithOvalInRect:CGRectMake((currentpoint.x-lineWidth),( currentpoint.y-lineWidth), lineWidth*2, lineWidth*2)];
NSInteger i,x,y;
NSInteger modNumber =5*(int)lineWidth;
for (i = 0; i < (lineWidth*lineWidth)/2; i++) {
do {
x = (random() % modNumber)+currentpoint.x - lineWidth*2;
y = (random() % modNumber)+currentpoint.y - lineWidth*2;
} while (![circle containsPoint:CGPointMake(x,y)]);
[path appendPath:[UIBezierPath bezierPathWithRect:CGRectMake(x,y,0.0025,0.0025)]];
}
[path moveToPoint:currentpoint];
[path setLineWidth:delegate.strokeWidth];
[path addLineToPoint:currentpoint];
// only if we actually remember the start of this touch...
}
[paths addObject:path];;
}
}
- (void)drawTemporary {
for (UIBezierPath *path in paths) {
[delegate.strokeColor setStroke];
[path stroke];
}
}
- (void)dealloc {
[trackingTouches release];
trackingTouches = nil;
[startPoints release];
startPoints = nil;
[paths release];
paths = nil;
self.delegate = nil;
[super dealloc];
}
-init{
if((self=[super init]))
{
trackingTouches=[[NSMutableArray]retain];
startPoints=[[NSMutableArray]retain];
路径=[[NSMutableArray]保留];
}
回归自我;
}
-(void)激活{}-(void)停用{
[trackingTouches removeAllObjects];
[startPoints removeAllObjects];
[路径移除所有对象];
}
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{
//UIView*touchedView=[用于工具的委托视图:self];
UITouch*触摸=[触摸任何对象];
UIView*touchedView=[用于工具的委托视图:self];
端点=[触摸位置视图:触摸视图];
用于(UITouch*触摸输入[事件所有触摸]){
//CGFloat线宽=10;
//记住触摸,以及它最初的起点,为了未来
[跟踪触摸添加对象:触摸];
CGPoint位置=[触摸位置视图:触摸视图];
[startPoints添加对象:[NSValue valueWithCGPoint:location];
UIBezierPath*路径=[UIBezierPath bezierPath];
path.lineCapStyle=kCGLineCapRound;
[路径移动点:位置];
[路径设置线宽:delegate.strokeWidth];
[路径addLineToPoint:位置];
[路径添加对象:路径];
}
}
-(无效)触控取消:(NSSet*)触控事件:(UIEvent*)事件{
[自失活];
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{
//UITouch*触摸=[触摸任何对象];
//UIView*touchedView=[用于工具的委托视图:self];
//端点=[触摸位置视图:触摸视图];
用于(UITouch*触摸输入[事件所有触摸])
{//从起点到当前点划一条线
NSUInteger touchIndex=[trackingTouches indexOfObject:touch];
//只有当我们真的记得触摸的开始。。。
如果(touchIndex!=NSNotFound){
UIBezierPath*path=[paths objectAtIndex:touchIndex];
PathDrawingInfo*info=[PathDrawingInfo-PathDrawingInfo-WithPath:path fillColor:[UIColor clearColor]strokeColor:delegate.strokeColor];
[可添加代理:信息];
[trackingTouches removeObjectAtIndex:touchIndex];
[startPoints RemoveObjectaIndex:touchIndex];
[路径RemoveObjectIndex:touchIndex];
}
}
}
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件{
//UIView*touchedView=[用于工具的委托视图:self];
UITouch*触摸=[触摸任何对象];
UIView*touchedView=[用于工具的委托视图:self];
currentpoint=[触摸位置视图:触摸视图];
//电流点y-=20;
//[自画圆圈];
用于(UITouch*触摸输入[事件所有触摸]){
CGFloat线宽=10;
//从起点到当前点划一条线
NSUInteger touchIndex=[trackingTouches indexOfObject:touch];
UIBezierPath*路径=[UIBezierPath bezierPath];
如果(touchIndex!=NSNotFound){
//CGPoint位置=[触摸位置视图:触摸视图];
UIBezierPath*path=[paths ObjectatinIndex:touchIndex];UIBezierPath*circle=[UIBezierPath BEZIERPATH WITHOVALINRECT:CGRectMake((currentpoint.x-lineWidth),(currentpoint.y-lineWidth),线宽*2,线宽*2)];
NSInteger i,x,y;
NSInteger modNumber=5*(int)线宽;
对于(i=0;i<(线宽*线宽)/2;i++){
做{
x=(random()%modNumber)+currentpoint.x-线宽*2;
y=(random()%modNumber)+currentpoint.y-线宽*2;
}而(![circle包含点:CGPointMake(x,y)];
[path appendPath:[UIBezierPath-bezierpath-withrect:CGRectMake(x,y,0.0025,0.0025)];
}
[路径移动点:当前点];
[路径设置线宽:delegate.strokeWidth];
[路径addLineToPoint:currentpoint];
//只有当我们真的记得触摸的开始。。。
}
[路径添加对象:路径];;
}
}
-(无效)临时提款{
对于(UIBezierPath*路径中的路径){
[delegate.strokeColor setStroke];
[路径笔划];
}
}
-(无效)解除锁定{
[跟踪触摸释放];
trackingTouches=零;
[起点发布];
起始点=零;
[路径释放];
路径=零;
self.delegate=nil;
[super dealoc];
}
在h块中定义属性并在m块中合成。
@属性(非原子,保留)NSMutableArray*trackingTouches
@属性(非原子,保留)NSMutableArray*起始点
@属性(非原子,保留)NSMutableArray*路径
@综合跟踪触控、起始点、路径
然后像这样使用dealoc块
- (void)dealloc {
[self setTrackingTouches:nil];
[self setStartPoints:nil];
[self setPaths:nil];
self.delegate = nil;
[super dealloc];
}
不要使用UIBezierPath。使用纯核心图形功能创建CGMutablePathRef。Spary工具是什么?从没听说过。当你独立运行你的应用程序时,它是否正常运行,也就是说没有任何工具在运行?它的Spary Can工具我已经编辑了我的问题。当我使用画笔、矩形等其他工具时,我的应用程序运行良好。我的应用程序也不会崩溃,但在使用喷雾罐工具后,速度会大大减慢。是的,我以前做过,但结果相同。将在此处更新我的代码。请使用合成和nil方法避免内存崩溃。我的应用程序不会崩溃,只是速度变慢了。我已经将这些变量声明为属性,我只发布了init函数中的代码。谢谢你的回复,我很高兴见到你