开发者

CGPath occupying more memory

This is a very much daunting challenge I have ever faced. Im drawing lines when the finger is moved. The lines are created such that they bypass the imageviews presnt in my drawingview. I`m using below code.

Code:-

-(void) paintLinesinContext:(CGContextRef)context{  
       for (Line *line in lines) {
        NSMutableArray *arrayOfPoints=[line getPointsArray];
        CGContextBeginPath(context);
        int numberofPoints=[arrayOfPoints count] ;
        开发者_开发问答CGPoint points[numberofPoints];
        int index=0;
        CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
        if (line==tmpline) {
            float dashPhase=10;
            float dashPattern[3]={5,5};
            CGContextSetLineDash(context, dashPhase, dashPattern, 2);
            CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
        }       
        for (NSValue *pointObject in arrayOfPoints) {
            points[index]= [pointObject CGPointValue];
            if (index==0) {
                CGContextMoveToPoint(context, points[index].x,points[index].y);
            }
            else {
                CGContextAddLineToPoint(context, points[index].x, points[index].y);
            }
            index++;
        }       
        CGContextStrokePath(context);
        float dashPhase=10;
        float dashPattern[3]={1,0};
        CGContextSetLineDash(context, dashPhase, dashPattern, 2);
    }
}

My problem is, my app is getting crashed because of low memory. When I looked into it using allocations in instruments, I noticed that CGPath is occupying more memory. Believe it or not. My app is running at 48MB and jumps to 96 MB out of which 90MB is CGPath. I don know what is the reason Can anyone help me out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜