ios - 我该如何解决这个漏洞?

标签 ios memory-leaks warnings

Analyzer 一直说我在开头和结尾处有 * 的行中有泄漏,我该如何修复此泄漏以消除警告?

+ (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];

    }
}

谢谢!

最佳答案

当您使用属性时,它们通常会执行适当的内存管理。在您的情况下,您需要自动释放您设置的类(class)。

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

关于ios - 我该如何解决这个漏洞?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7020131/

相关文章:

iOS 在辅助方法中初始化并返回一个新对象

ios - 警告 : attempt to present

ios - 4.2 中 iAd 变化的问题

ios - 如何将数据传递给嵌入在导航 Controller 中的 Collection View Controller

ios - 隐藏不需要的日志打印 - 在 Xcode 9 中

c++11 - 无法消除共享指针泄漏的递归解析代码

java - 从数据库中读取 +800 万条记录的内存泄漏

objective-c - 如何解决 fileAttributesAtPath 警告的问题?

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

ios - 64 位 iOS 设备中的 UIViewControllerHierarchyInconsistency