我的內存警告與我的應用程序然後崩潰。錯誤,我認爲是在我的觸摸式功能上,因爲當我試圖用alloc工具運行它時,當我繼續在屏幕上移動手指時,內存開始增加。目標C:在ARC上收到內存警告
這是我的代碼。
touchSwiped = YES;
UITouch *touch = [touches anyObject];
previousPoint2 = previousPoint1;
previousPoint1 = currentTouch;
currentTouch = [touch locationInView:self.view];
CGPoint mid1 = midPoint(previousPoint2, previousPoint1);
CGPoint mid2 = midPoint(currentTouch, previousPoint1);
UIGraphicsBeginImageContext(CGSizeMake(480 , 320));
[drawView.image drawInRect:CGRectMake(0, 0, 480,320)];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineCap(context,kCGLineCapRound);
CGContextSetLineWidth(context, inkWidth);
CGContextSetBlendMode(context, blendMode);
CGContextSetRGBStrokeColor(context,redColor, greenColor, blueColor, 1);
CGContextBeginPath(context);
CGContextMoveToPoint(context, mid1.x, mid1.y);
CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
CGContextStrokePath(context);
drawView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsGetCurrentContext();
您正在爲每次觸摸/拖動創建大量東西,即使使用ARC,我也相信您必須發佈CGContextRef和其他一些東西。我不完全確定,因此這是一條評論。祝你好運! – ohr 2012-08-14 03:24:07
你是半正確的@oohr。核心圖形和核心基礎「對象」不是由ARC管理的內存,但是你從'UIGraphicsGetCurrentContext()'得到的'CGContextRef'不是被調用者擁有的(該函數沒有'copy'或'create '在其名稱中](http://developer.apple.com/library/ios/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029)),並且不不必被釋放。 – 2012-08-14 03:41:20
@ohr它的工作!謝謝! – SeongHo 2012-08-14 03:41:27