tags:

views:

43

answers:

1
    -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
        UITouch *touch=[touches anyObject];
        currentPoint=[touch locationInView:self.view];
        rootLayer   = [CALayer layer];
        rootLayer.frame = self.view.bounds;
        [self.view.layer addSublayer:rootLayer];
        starPath = CGPathCreateMutable();
        CGPathMoveToPoint(starPath, NULL, currentPoint.x, currentPoint.y + 15.0);
        for(int i = 1; i < 5; ++i)
        {
        CGFloat x =  15.0 * sinf(i * 4.0 * M_PI / 5.0);
        CGFloat y =  15.0 * cosf(i * 4.0 * M_PI / 5.0);
        CGPathAddLineToPoint(starPath, NULL, currentPoint.x + x, currentPoint.y + y);
        }
        CGPathCloseSubpath(starPath);
        shapeLayer = [CAShapeLayer layer];
        shapeLayer.path = starPath;
        UIColor *fillColor = [UIColor colorWithWhite:0.9 alpha:1.0];
        shapeLayer.fillColor = fillColor.CGColor; 
        [rootLayer addSublayer:shapeLayer];
    }


    - (void)dealloc {
        [imageView release];
        CGPathRelease(starPath);
        [super dealloc];
    }

When i am running with performance tool leaks it occupying more memory

when iam moving ....

what to do....

i need to draw this star shape on touches movies on the layer so i can perform animations later ....

A: 

You're releasing the path in dealloc, but creating it (potentially) many times inside your touchesMoved:. You can safely release this resource at the end of your touchesMoved:, please consider doing that.

Also, after you've made that change, you can remove the release from dealloc, since you will never have to release it there any longer. Your path doesn't exist outside your method.

jer
@jer thanks for replay.. i did in that way too... but still in my instruments all allocation increase when i moved.... its not controlled......
kiran kumar
@Kiran why you've declared starpath as a global variable? And jer's answer is correct. You just need to release starpath inside touches moved method itself.
Sagar