xCode 内存泄漏,尽管释放了对象?
下面是一个简单的函数,它接受日期作为字符串,将其转换为正确的日期格式并将其作为 NSDate 返回。
-(NSDate*) dateLabelSet:(NSString*)strDate
{
NSDate *activeDate;
NSDateFormatter *format;
format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
activeDate = [format dateFromString:strDate];
[format release];
return activeDate;
}
当我通过仪器中的泄漏运行此函数时,它表示格式存在泄漏。该函数看起来相对简单...在本地声明格式,使用它,并在返回日期之前释放它。
有人有什么建议吗?
非常感谢!
Below is a simple function that accepts a date as a string, converts it to a proper date format and returns it as a NSDate
-(NSDate*) dateLabelSet:(NSString*)strDate
{
NSDate *activeDate;
NSDateFormatter *format;
format = [[NSDateFormatter alloc] init];
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
activeDate = [format dateFromString:strDate];
[format release];
return activeDate;
}
When I run this through leaks in instruments, it is saying that format is leaky. The function seems relatively straight forward... Declares format locally, utilizes it, and releases it before returning the date.
Anyone have any suggestions?
Much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这是 NSDateFormatter 类中的内部内存泄漏,就像 NSString 类中的 [NSString stringByAppending...] 方法中一样。我们对此无能为力。
I think this is an internal memory leak in NSDateFormatter class, like in [NSString stringByAppending...] methods in NSString class. Nothing we can do about it.