开发者

Memory leak in TBXML iOS Parser

I am using TBXML for XML feed parsing and instruments to detect memory leaks.

Instruments tells me there is a memory leak in function

- (TBXMLAttribute*) nextAvailableAttribute {
currentAttribute++;

if (!currentAttributeBuffer) {
currentAttributeBuffer = calloc(1, sizeof(TBXMLAttributeBuffer));
currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));
currentAttribute = 0;
} else if (currentAttribute >= MAX_ATTRIBUTES) {
currentAttributeBuffer->next = calloc(1, sizeof(TBXMLAttributeBuffer));
currentAttributeBuffer->next->previous = currentAttributeBuffer;
currentAttributeBuffer = currentAttributeBuffer->next;
currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));
currentAttribute = 0;
}

return &currentAttributeBuffer->attributes[currentAttr开发者_JAVA百科ibute];
}

at the line

currentAttributeBuffer->attributes = (TBXMLAttribute*)calloc(MAX_ATTRIBUTES,sizeof(TBXMLAttribute));

Does any one solved it before?


BEWARE.... instruments is telling you WHERE the leaked memory was originally created, NOT that the issue is in that line... for instance, if you do something with the attribute returned and leak it elsewhere, instruments will show THE line above, where it was created, NOT where you leaked it....


calloc is a C function to allocate memory. You should call free currentAttributeBuffer; when you're finished with it. That will fix the memory leak.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜