gpt4 book ai didi

iphone - 将字符串提供给对象时泄漏字符串

转载 作者:行者123 更新时间:2023-11-29 11:22:51 24 4
gpt4 key购买 nike

我收到了可追溯到以下方法的 NSCFSting 泄漏。我正在解析一个 XML 文件,并使用从 textForElement 获得的字符串并将它们设置为对象 (EventArticleObject) 中的变量。我知道泄漏不是来自 textForElement,因为我在另一个没有将字符串设置为对象的解析方法中没有泄漏。

我填充的数组和字典没有泄露,只是字符串。当我转到 Stack Trace 并单击其中一个泄漏的字符串时,显示如下: pic#2 CFRetain 追溯到下面方法中的 setLink,这就是我认为我在使用对象时做错了什么。

有没有人看到我在这里做错了什么?非常感谢!

//Parse the weekly events are store. Must first get the date, format it, and attach it to
// the link; this is to get the events for the current week.
- (void)parseWeekEvents
{

TBXML *tbxml;
TBXMLElement *rootXMLElement;
TBXMLElement *node_channel;
TBXMLElement *node_item;
TBXMLElement *node_traverse;

NSString *fullEventURL;
fullEventURL = @"http://www.millersville.edu/calendar/rss.php?q=&c=&date=";
fullEventURL = [fullEventURL stringByAppendingString:dateURL];
fullEventURL = [fullEventURL stringByAppendingString:@"&mode=week"];

eventsDict = [[NSMutableDictionary alloc] init];
datesArray = [[NSMutableArray alloc] init];

tbxml = [TBXML tbxmlWithURL:[NSURL URLWithString:fullEventURL]];
rootXMLElement = tbxml.rootXMLElement;

if(rootXMLElement)
{
node_channel = [TBXML childElementNamed:@"channel" parentElement:rootXMLElement];

if(node_channel)
{
node_item = [TBXML childElementNamed:@"item" parentElement:node_channel];

while(node_item)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

EventArticleObject *currentEvent = [[[EventArticleObject alloc] init] autorelease];

NSString *title;
NSString *link;
NSString *date;

node_traverse = [TBXML childElementNamed:@"title" parentElement:node_item];
title = [TBXML textForElement:node_traverse];
title = [title stringByReplacingOccurrencesOfString:@"&" withString:@"&"];
title = [title stringByReplacingOccurrencesOfString:@"'" withString:@"'"];

[currentEvent setTitle:title];

node_traverse = [TBXML childElementNamed:@"link" parentElement:node_item];
link = [TBXML textForElement:node_traverse];
[currentEvent setLink:link];

node_traverse = [TBXML childElementNamed:@"pubDate" parentElement:node_item];
date = [TBXML textForElement:node_traverse];
NSRange stringRange = {0,16};
date = [date substringWithRange:stringRange];
[currentEvent setDate:date];

if(![datesArray containsObject:date])
{
[datesArray addObject:date];
}

NSString *eventDate = [currentEvent date];
NSMutableArray *temp = [eventsDict objectForKey:eventDate];
if(!temp)
{
temp = [NSMutableArray array];
[temp addObject:currentEvent];
[eventsDict setObject:temp forKey:eventDate];
} else {
[temp addObject:currentEvent];
}
node_item = node_item -> nextSibling;

[pool drain];
}
}
}
}

这是我的 EventArticleObject.m:

@implementation EventArticleObject

@synthesize link, date, title;

- (id)initWithTitle:(NSString *)title2
date:(NSString *)date2
link:(NSString *)link2;
{
self = [super init];
if(!self)
return nil;

[self setLink:link2];
[self setDate:date2];
[self setTitle:title2];

return self;
}

@end

最佳答案

验证EventArticleObject类是否所有变量都正确释放

关于iphone - 将字符串提供给对象时泄漏字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5978943/

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