我正在制作一个使用SKMap(Skobbler)的iOS应用程序.当SKMap打开时,我的应用会占用大量内存.当我移动到应用程序的其他页面时,更多内容不会释放内存.
我在viewWillDisappear方法中放了一些代码来释放SKMap的内存,
[[SKRoutingService sharedInstance].mapView clearAllAnnotations];
[SKRoutingService sharedInstance].routingDelegate = nil;
[SKRoutingService sharedInstance].navigationDelegate=nil;
[[AudioService sharedInstance]cancel];
[[SKRoutingService sharedInstance]stopNavigation];
[[SKRoutingService sharedInstance]clearCurrentRoutes];
[[SKRoutingService sharedInstance]clearAllRoutesFromCache];
[SKRoutingService sharedInstance].mapView = nil;
//self.mapView is SKMap
self.mapView.settings.displayMode = SKMapDisplayMode2D;
self.mapView.delegate=nil;
[self.mapView removeFromSuperview];
self.mapView=nil;
Run Code Online (Sandbox Code Playgroud)
如果您有任何解决方案来释放内存,请帮助我.
嘿我正在开发一个应用程序,我必须每隔30秒进行一次API调用,所以我为它创建了NSTimer.但当我的应用程序进入后台计时器后3-4分钟停止发射.因此它在后台只能工作3-4分钟,但之后却没有.如何修改我的代码,以便计时器不会停止.
这是我的一些代码.
- (IBAction)didTapStart:(id)sender {
NSLog(@"hey i m in the timer ..%@",[NSDate date]);
[objTimer invalidate];
objTimer=nil;
UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
UIApplication *app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
}];
objTimer = [NSTimer scheduledTimerWithTimeInterval:30.0 target:self
selector:@selector(methodFromTimer) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:objTimer forMode:UITrackingRunLoopMode];
}
-(void)methodFromTimer{
[LOG debug:@"ViewController.m ::methodFromTimer " Message:[NSString stringWithFormat:@"hey i m from timer ....%@",[NSDate date] ]];
NSLog(@"hey i m from timer ....%@",[NSDate date]);
}
Run Code Online (Sandbox Code Playgroud)
我甚至用以下内容更改了代码:
[[NSRunLoop mainRunLoop] addTimer:objTimer forMode:NSRunLoopCommonModes];
Run Code Online (Sandbox Code Playgroud)
这也不起作用.