Iphone simpleftp中的内存泄漏

Iphone simpleftp中的内存泄漏,iphone,objective-c,memory-leaks,Iphone,Objective C,Memory Leaks,我使用请求文档信息。我使用以下仪器检测内存泄漏: - (void)_parseListData { NSMutableArray * newEntries; NSUInteger offset; // We accumulate the new entries into an array to avoid a) adding items to the // table one-by-one, and b) repeatedly shuf

我使用请求文档信息。我使用以下仪器检测内存泄漏:

- (void)_parseListData
{
    NSMutableArray *    newEntries;
    NSUInteger          offset;

    // We accumulate the new entries into an array to avoid a) adding items to the 
    // table one-by-one, and b) repeatedly shuffling the listData buffer around.

    newEntries = [NSMutableArray array];
    assert(newEntries != nil);

    offset = 0;
    do {
        CFIndex         bytesConsumed;
        CFDictionaryRef thisEntry;

        thisEntry = NULL;

        assert(offset <= self.listData.length);
        bytesConsumed = CFFTPCreateParsedResourceListing(NULL, &((const uint8_t *) self.listData.bytes) [offset], self.listData.length - offset, &thisEntry);
        if (bytesConsumed > 0) {
........
}
在调用树中,我发现内存泄漏发生在哪里:

方法parseListData如下所示:

- (void)_parseListData
{
    NSMutableArray *    newEntries;
    NSUInteger          offset;

    // We accumulate the new entries into an array to avoid a) adding items to the 
    // table one-by-one, and b) repeatedly shuffling the listData buffer around.

    newEntries = [NSMutableArray array];
    assert(newEntries != nil);

    offset = 0;
    do {
        CFIndex         bytesConsumed;
        CFDictionaryRef thisEntry;

        thisEntry = NULL;

        assert(offset <= self.listData.length);
        bytesConsumed = CFFTPCreateParsedResourceListing(NULL, &((const uint8_t *) self.listData.bytes) [offset], self.listData.length - offset, &thisEntry);
        if (bytesConsumed > 0) {
........
}
我不知道如何解决这个问题

方法CFFTPCreateParsedResourceListing是一个系统方法,它创建了第二个pic

这就是内存泄漏发生的地方。

CFFTPCreateParsedResourceList函数将CFDictionary返回到thisEntry变量中,该变量可能包含NSDate对象

完成后,代码应在此条目上调用CFRelease:

// once we're done with thisEntry
if (thisEntry) {
    CFRelease(thisEntry);
}

旧帖子,但有用的解决方案。你可以在这里找到答案。 根据创建者的说法,CFFTPCreateParsedResourceList方法保留两倍的NSDate,要覆盖添加下一个代码的问题,请注意此处的注释: 实际上,在Whiteracoon中,如果您列出一个目录,您将泄漏NSDate的。苹果SDK中的函数CFFTPCreateParsedResourceList存在漏洞。我已经尝试修补这个,但是它不能保证工作。对于OS5.1来说,它确实有效

            ........
            if (parsedBytes > 0)
            {
                if (listingEntity != NULL)
                {
                    //----- July 10, 2012: CFFTPCreateParsedResourceListing had a bug that had the date over retained
                    //----- in order to fix this, we release it once. However, just as a precaution, we check to see what
                    //----- the retain count might be (this isn't guaranteed to work).
                    id date = [(__bridge NSDictionary *) listingEntity objectForKey: (id) kCFFTPResourceModDate];
                    if (CFGetRetainCount((__bridge CFTypeRef) date) >= 2)
                        CFRelease((__bridge CFTypeRef) date);

这对我有效

此代码已包含在此函数中,如:if thisEntry!=NULL{CFReleasethisEntry;}我只是绕过它是的,这是一个令人讨厌的,令人讨厌的,我写的黑客为了绕过漏洞。它似乎适用于iOS 5和iOS 6。我不能说它是否适用于iOS 7。