【发布时间】:2015-03-12 13:36:24
【问题描述】:
我正在尝试调试一个困难的内存泄漏。在 MyAppDelegate.m 中,我有
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.notificationTimer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(syncNotifications:)
userInfo:nil
repeats:YES];
return YES;
}
- (void)syncNotifications:(NSTimer*)timer {
NSString *path = @"http://example";
NSLog(@"GET: %@", path);
AFHTTPRequestOperationManager *network = [AFHTTPRequestOperationManager manager];
[network GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"get success");
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
我发现内存泄漏的速率约为 1MB / 3 秒。我尝试将网络设置为属性。还尝试如下注释掉实际的网络请求:
- (void)syncNotifications:(NSTimer*)timer {
NSString *path = @"http://example";
NSLog(@"GET: %@", path);
AFHTTPRequestOperationManager *network = [AFHTTPRequestOperationManager manager];
}
虽然我没有看到太多内存泄漏,但我仍然看到 Instruments 面板中的内存分配在攀升。在 NSTimers 的内存管理方面,我是否遗漏了什么?
【问题讨论】:
标签: ios objective-c memory memory-leaks