仪器(Leaks)和NSDateFormatter [英] Instruments (Leaks) and NSDateFormatter

查看:148
本文介绍了仪器(Leaks)和NSDateFormatter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Instruments Leaks运行我的iPhone应用程序并使用NSDateFormatter解析一堆NSDates时,我的内存大约增加1mb并保持不变,即使这些NSDates在解析后应该被释放(如果它们不是,我只是丢弃它们)新的)。

When I run my iPhone app with Instruments Leaks and parse a bunch of NSDates using NSDateFormatter my memory goes up about 1mb and stays even though these NSDates should be dealloc'd after the parsing (I just discard them if they aren't new).

我认为malloc(在我下面最重的堆栈跟踪中)可以成为NSDate的一部分,但我也认为它可能是仅在某些中间使用的内存一步解析。有谁知道它是哪一个或如何找出?

I thought the malloc (in my heaviest stack trace below) could become part of the NSDate but I also thought it could be memory that only used during some intermediate step in parsing. Does anyone know which one it is or how to find out?

此外,有没有办法在NSDate dealloc上放置一个断点来查看该内存是否真的被回收?

Also, is there a way to put a breakpoint on NSDate dealloc to see if that memory is really being reclaimed?

以下是我的日期格式化程序解析这些日期的样子:

Here's what my date formatter looks like for parsing these dates:

df = [[NSDateFormatter alloc] init]; 
[df setDateFormat:@"EEE, d MMM yyyy H:m:s z"];

当内存崩溃并停留在那里时,这是最重的堆栈跟踪:

Here's the Heaviest Stack trace when the memory bumps up and stays there:

   0 libSystem.B.dylib  208.80 Kb     malloc
   1 libicucore.A.dylib  868.19 Kb     icu::ZoneMeta::getSingleCountry(icu::UnicodeString const&, icu::UnicodeString&)
   2 libicucore.A.dylib  868.66 Kb     icu::ZoneMeta::getSingleCountry(icu::UnicodeString const&, icu::UnicodeString&)
   3 libicucore.A.dylib  868.67 Kb     icu::ZoneMeta::getSingleCountry(icu::UnicodeString const&, icu::UnicodeString&)
   4 libicucore.A.dylib  868.67 Kb     icu::DateFormatSymbols::initZoneStringFormat()
   5 libicucore.A.dylib  868.67 Kb     icu::DateFormatSymbols::getZoneStringFormat() const
   6 libicucore.A.dylib  868.67 Kb     icu::SimpleDateFormat::subParse(icu::UnicodeString const&, int&, unsigned short, int, signed char, signed char, signed char*, icu::Calendar&) const
   7 libicucore.A.dylib  868.67 Kb     icu::SimpleDateFormat::parse(icu::UnicodeString const&, icu::Calendar&, icu::ParsePosition&) const
   8 libicucore.A.dylib  868.67 Kb     icu::DateFormat::parse(icu::UnicodeString const&, icu::ParsePosition&) const
   9 libicucore.A.dylib  868.67 Kb     udat_parse
  10 CoreFoundation  868.67 Kb     CFDateFormatterGetAbsoluteTimeFromString
  11 CoreFoundation  868.67 Kb     CFDateFormatterCreateDateFromString
  12 Foundation  868.67 Kb     -[NSDateFormatter getObjectValue:forString:range:error:]
  13 Foundation  868.75 Kb     -[NSDateFormatter getObjectValue:forString:errorDescription:]
  14 Foundation  868.75 Kb     -[NSDateFormatter dateFromString:]

谢谢!

推荐答案

[df setDateFormat:@"EEE, d MMM yyyy H:m:s z"]; // Remove the `z`

868 Kb将在iPhone OS 2.2.1或3.1上永久分配使用z选项时,在单次调用dateFromString之后的.2(更多信息)。

868 Kb will be permanently allocated on iPhone OS 2.2.1 or 3.1.2 (more to come) after a single invocation to "dateFromString" when the z option is used.

可以阅读包含源代码和日志文件的完整文章
http://thegothicparty.com/dev/article/nsdateformatter-memory -leak /

A complete article with source code and log file can be read at http://thegothicparty.com/dev/article/nsdateformatter-memory-leak/

这篇关于仪器(Leaks)和NSDateFormatter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆