誰かが私がここで間違っていることを教えてもらえますか?私はイメージを描画するためにこのメソッドを使用します。しかし、コード内の何かは、私がこのメソッドを呼び出すたびに、そしてアプリケーションメモリのフットプリントが増えるため、適切に解放されないようです。iPhone:メモリ管理
ここでは、私の記憶を増やす方法を提供しています。
-(void)imagemaking
{
UIGraphicsEndImageContext();
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
SBJSON *parser = [[SBJSON alloc] init];
statuses = [parser objectWithString:responseString
error:nil];
[parser release];
networkConnection.image = [UIImage imageNamed:@"NetworkTrans1.png"];
[updateTimeClock setImage:[UIImage imageNamed:@"GreenClock.png"] forState:UIControlStateNormal];
NSArray *segment = [[NSArray alloc]init];
segment = [statuses valueForKey:@"Segments"];
int linewidth = 3;
CGSize polyimagesize = CGSizeMake(self.mapView.frame.size.width , self.mapView.frame.size.height);
UIGraphicsBeginImageContextWithOptions(polyimagesize, NO, 0);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, linewidth);
CGContextSetAlpha(context, 0.6);
for(NSDictionary *route in segment) {
NSString *locations = [route valueForKey:@"Locations"];
if (locations && ([locations length]/16 > 1)) {
UIColor *color = [UIColor blueColor];
CGContextSetStrokeColorWithColor(context, color.CGColor);
for (int i = 0; i <= locations.length - 32; i += 32) {
CLLocationCoordinate2D coordinates;
coordinates.latitude = hexDecode_iPhone([locations substringWithRange:NSMakeRange(i, 16)]);
coordinates.longitude = hexDecode_iPhone([locations substringWithRange:NSMakeRange(i+16, 16)]);
CGPoint point = [mapView convertCoordinate:coordinates toPointToView:self.mapView];
if (i == 0)
CGContextMoveToPoint(context, point.x, point.y);
else
CGContextAddLineToPoint(context, point.x, point.y);
}
CGContextStrokePath(context);
}
}
madeimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[responseString release];
[segment release];
}私の調査を1として
、理由CoreGraphics.Butのメモリフットプリントの増加私は、メモリの使用量を削減する方法がわからないか、そのオブジェクトがメモリusage.Pleaseガイドラインを提供増加であります。
ありがとうございます!
私は最初に全体のコードを実行する必要があります。関数の最後にセグメントをリリースします。私は計器の助けを借りて全体で10回のチェックを行い、アプリケーションにリークがないことがわかりました。 – Nit
あなたは何か他のものをリリースしています。 – jacekmigacz
@Nit: 'valueForKey:'によって返された配列を解放しますが、 'alloc'と' init'によって返される配列は解放しません。それらは2つの別個の配列オブジェクトで、すぐに最初のものを2番目のものに置き換えて、最初のものをリークします。別のリークがあっても(あなたが示したコードでは見えません)、jacekmigaczの答えは正しいです。 –