Может кто-нибудь сказать мне, что я здесь делаю не так? Я использую этот метод для рисования изображения. Но что-то в коде, кажется, не высвобождается должным образом, потому что каждый раз, когда я вызываю этот метод, и объем памяти моего приложения увеличивается.
Здесь я предоставляю метод, который увеличивает мою память.
-(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];
}
Согласно моему исследованию, след памяти увеличивается из-за CoreGraphics. Но я не знаю, как уменьшить использование памяти или какой объект увеличивает использование памяти. Пожалуйста, предоставьте руководство.
Заранее спасибо!