我们开发了地图基础应用程序。我们在地图视图上实现了多线程显示数据。应用程序运行时间较长(大约20分钟)时,应用程序将显示内存警告级别1。在几分钟后,它会给内存警告级别2,在level2应用程序崩溃或进入睡眠状态之后。我们如何处理iPhone中的内存级警告?
我们已经检查了内存泄漏,僵尸很多的时间。但是在我们的应用程序中没有内存泄漏和僵尸。
请指点如何处理内存警告级别。请画出一些线来克服内存级警告。
////更新... 我发现,内存使用率增加,因为
CGContextRef context = UIGraphicsGetCurrentContext();
我已经使用了多线程的平局聚注释并为我所用CGContextRef这增加了我的内存使用情况每当我打电话时。
我不知道如何释放背景下,因为如果我释放比下一次它显示我
无效的上下文错误我感到我并主张绘图代码here.Please帮助我,如果任何人有任何想法。
-(void) drawRect:(CGRect)rect {
NVPolylineAnnotation* annotation = self.annotation;
CGFloat POLYLINE_WIDTH = 9;
if(annotation.getZoomLevel == 7) {
POLYLINE_WIDTH = 1.5;
}
else if(annotation.getZoomLevel == 8) {
POLYLINE_WIDTH = 2.5;
}
else if(annotation.getZoomLevel ==9) {
POLYLINE_WIDTH = 3;
}
else if(annotation.getZoomLevel ==10) {
POLYLINE_WIDTH = 3.4;
}
else if(annotation.getZoomLevel == 11) {
POLYLINE_WIDTH = 4;
}
else if(annotation.getZoomLevel <= 13) {
POLYLINE_WIDTH = 4.3;
}
else if (annotation.getZoomLevel == 14) {
POLYLINE_WIDTH = 5.4;
}
else if(annotation.getZoomLevel == 15) {
POLYLINE_WIDTH = 8;
}
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
CGContextSetLineWidth(context, POLYLINE_WIDTH);
CGContextSetAlpha(context, 0.6);
for(NSDictionary *route in annotation.routes) {
NSString *locations = [route valueForKey:@"Locations"];
double speed = [[route valueForKey:@"Speed"] doubleValue];
if (locations && ([locations length]/16 > 1)) {
UIColor *color;
if (speed <= 20) {
color = [UIColor colorWithRed:222/255.0 green:0/255.0 blue:0/255.0 alpha:1.0];
}
else if (speed <= 40) {
color = [UIColor colorWithRed:253/255.0 green:91/255.0 blue:2/255.0 alpha:1.0];
}
else if (speed <= 60) {
color = [UIColor colorWithRed:253/255.0 green:145/255.0 blue:4/255.0 alpha:1.0];
}
else if (speed <=80) {
color = [UIColor colorWithRed:255/255.0 green:212/255.0 blue:4/255.0 alpha:1.0];
}
else if (speed >80) {
color = [UIColor colorWithRed:42/255.0 green:176/255.0 blue:39/255.0 alpha:1.0];
}
CGContextSetStrokeColorWithColor(context, color.CGColor);
for (int i = 0; i <= locations.length - 32; i += 32) {
CLLocationCoordinate2D coordinates;
coordinates.latitude = hexDecode([locations substringWithRange:NSMakeRange(i, 16)]);
coordinates.longitude = hexDecode([locations substringWithRange:NSMakeRange(i+16, 16)]);
CGPoint point = [_mapView convertCoordinate:coordinates toPointToView:self];
if (i == 0)
CGContextMoveToPoint(context, point.x, point.y);
else
CGContextAddLineToPoint(context, point.x, point.y);
}
[self setNeedsDisplay];
CGContextStrokePath(context);
}
}
context = NULL;
UIGraphicsEndImageContext();
}
在此先感谢。
你有什么首位试过吗?首先在Google中搜索**“处理iOS内存警告”**。 – 2012-03-14 04:39:37
@ParthBhatt:我做了,发现这个http://stackoverflow.com/questions/5980636/ios-low-memory-crash-but-very-low-memory-usage – Nit 2012-03-14 04:50:39
释放所有在ViewDidUnload网点()方法。 – 2012-03-14 04:52:18