当我尝试释放路径时,它将导致大约5兆字节的内存泄漏。每当我调用CGreleasePath时,ram内存使用量将再次增加5兆字节。可能是导致此内存泄漏的原因是什么?
这是我的所有路径都被使用的代码:
//viewcontroller.h
CGMutablePathRef path;
//viewcontroller.m
-(void)viewDidLoad{
path = CGPathCreateMutable;
timer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(movement1) userInfo:nil repeats:YES];
timer2 = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(motor) userInfo:nil repeats:YES];
}
-(void)movement1{
CGPathMoveToPoint(path, NULL, greentmporary.x, greentmporary.y);
CGPathAddLineToPoint(path, NULL, greenpoint1.x, greenpoint1.y);
}
-(void)motor{
CGPathRef thickpath = NULL;
thickpath = CGPathCreateCopyByStrokingPath(path, NULL, (6+bigsizeYellow), kCGLineCapSquare, kCGLineJoinMiter, 0);
if (CGPathContainsPoint(thickpath, NULL, greenpoint1, NO) && krockamedgreen == NO) {
NSLog(@"YES");
[self reset]
}
if (CGPathContainsPoint(thickpath, NULL, point1, NO) && krockamedgreen == NO) {
NSLog(@"YES");
[self reset]
}
if (thickpath) {
CFRelease(thickpath);
thickpath = NULL;
}
}
-(void)reset{
path = NULL;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//start again
{
path = CGPathCreateMutable;
}