- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict{
//currentElenet is NSString
currentElement = [elementName copy];
if ([elementName isEqualToString:@"struct"]) {
self.post = [[Question alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
if ([currentElement isEqualToString:@"string"]) {
post.text = [NSString stringWithFormat:@"%@ %@", post.text, string];
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"struct"]) {
[conversations addObject:post];
[post release];
post = nil;
}
}
//Question.m file
@synthesize text
-(id)init{
self = [super init];
if (self == nil) {
}
else {
//declared as retain in .h file
text = [[NSString alloc]initWithString:@""];
}
return self;
}
-(void)dealloc{
[super dealloc];
[title release];
}
你們看到有什麼記憶在這裏泄漏嗎?我調用NSXML委託方法,它基本上把一個「問題」的實例放入NSMutableArray中。我檢查過儀器,解析它時發現內存泄漏。但我不明白爲什麼...目標C,內存泄漏?