我有以下功能,这会导致*timeString
内存泄漏。我对Objective-C(和内存管理)相当陌生,但我读到您只需要首先release
使用您的对象alloc
。因为 I alloc
*formatter
,然后将其设置为*timeString
,这是否意味着我现在也必须释放*timeString
?
这是代码:
-(NSString *)getDate{
NSLog(@"getDate");
NSDateFormatter *formatter;
NSString *timeString;
formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd"];
timeString = [formatter stringFromDate:[NSDate date]];
[formatter release];
return timeString;
}
编辑:这里是getDate
调用函数的地方:
-(NSString *)getFileName{
//nameofXMLFile = page_##
NSString *nameOfFile = [NSString stringWithString:pageTitle];
//nameOfXMLFile = page_##.DataCheckSheet.xml
nameOfFile = [nameOfFile stringByAppendingString: @".DataCheckSheet.xml"];
NSString *dateString = [self getDate];
dateString = [dateString stringByAppendingString: @"_"];
NSLog(@"datestring: %@", dateString);
dateString = [dateString stringByAppendingString:nameOfFile];
NSLog(@"datestring with append: %@", dateString);
//nameOfXMLFile = yyyy-MM-dd_page_##.DataCheckSheet.xml
nameOfFile = dateString;
return nameOfFile;
}