gpt4 book ai didi

iphone - TBXML iOS 解析器中的内存泄漏

转载 作者:行者123 更新时间:2023-11-29 05:03:20 26 4
gpt4 key购买 nike

我正在使用 TBXML 进行 XML feed 解析,并使用工具来检测内存泄漏。

仪器告诉我函数中存在内存泄漏

- (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[currentAttribute];
}

在线

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

有人解决过这个问题吗?

最佳答案

注意...仪器告诉您泄漏的内存最初是在哪里创建的,而不是问题出在该行...例如,如果您对返回的属性执行某些操作并将其泄漏到其他地方,仪器将显示上面的行,它是在哪里创建的,而不是你泄露它的地方......

关于iphone - TBXML iOS 解析器中的内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6307242/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com