2011-08-11 129 views
1

分析仪总是说我在开始和结束时都有一条与*一致的泄漏线,我该如何解决这个泄漏问题,以免它发出警告?如何解决此泄漏问题?

+ (void)flushOfflineQueue 
{ 
    // TODO - if an item fails, after all items are shared, it should present a summary view and allow them to see which items failed/succeeded 

    // Check for a connection 
    if (![self connected]) 
     return; 

    // Open list 
    NSMutableArray *queueList = [self getOfflineQueueList]; 

    // Run through each item in the quietly in the background 
    // TODO - Is this the best behavior? Instead, should the user confirm sending these again? Maybe only if it has been X days since they were saved? 
    //  - want to avoid a user being suprised by a post to Twitter if that happens long after they forgot they even shared it. 
    if (queueList != nil) 
    { 
     SHK *helper = [self currentHelper]; 

     if (helper.offlineQueue == nil) 
      ***helper.offlineQueue = [[NSOperationQueue alloc] init];*** 

     SHKItem *item; 
     NSString *sharerId, *uid; 

     for (NSDictionary *entry in queueList) 
     { 
      item = [SHKItem itemFromDictionary:[entry objectForKey:@"item"]]; 
      sharerId = [entry objectForKey:@"sharer"]; 
      uid = [entry objectForKey:@"uid"]; 

      if (item != nil && sharerId != nil) 
       [helper.offlineQueue addOperation:[[[SHKOfflineSharer alloc] initWithItem:item forSharer:sharerId uid:uid] autorelease]]; 
     } 

     // Remove offline queue - TODO: only do this if everything was successful? 
     [[NSFileManager defaultManager] removeItemAtPath:[self offlineQueueListPath] error:nil]; 

    } 
} 

谢谢!

回答

1

当您使用属性时,他们通常会执行正确的内存管理。在你的情况下,你需要autorelease你设置的类。

helper.offlineQueue = [[[NSOperationQueue alloc] init] autorelease]; 
+0

谢谢!我会在9分钟内接受这个答案 –