为什么我的应用程序只使用了大约36MB内存,但我仍然收到低内存警告?

时间:2010-08-09 09:50:52

标签: iphone memory ipad

我使用仪器来跟踪我的应用程序的内存使用情况,在内存监视器中,我发现实际内存低于36MB,大部分时间只有32MB,但我仍然收到组织者内存低位警告和崩溃的警告。

Incident Identifier: CFEF044E-E839-4DB7-9ED6-E22CD92B9171
CrashReporter Key:   80954447762f1882da7df309d5493cf8647f4c8b
OS Version:          iPhone OS 3.2 (7B367)
Date:                2010-08-10 15:21:25 +0800

Free pages:        593
Wired pages:       18705
Purgeable pages:   1664
Largest process:   iPad4HB

Processes
         Name                 UUID                    Count resident pages
         iPad4HB <51ec4f748adb8d99e4456ba49644e516>   27182 (jettisoned) (active)
     debugserver <6f10136b8d55ad8cbd29c09a402b1f94>     149
    syslog_relay <4ceaed776d2df957fa130712f4ef21d0>      70
notification_pro <4c9a7ee0a5bbe160465991228f2d2f2e>      71
             lsd <a4d852c1c8da2b3d231bdc90887b52ba>     143
            apsd <f655e615956fa9881fd423d762791e7d>     197
         notifyd <5e9d5bee7c3eae1c8b494c79eb11406e>      62
        BTServer <64e4a6ea6b1240db2331e05a29caa862>     132
      CommCenter <97bf297944ac4bde19bcee96dd23bd5f>     191
     SpringBoard <c7a5904c12db7b14334a4edaa4cabaa9>    4844 (active)
      accessoryd <b4e1403f53e4c7b53b0ec833007f6589>     122
         configd <aca9fa3380322669164fd6b1a3864300>     374
   fairplayd.K48 <2d997ffca1a568f9c5400ac32d8f0782>      86
       locationd <dd1ea88105c62173908ce767db5c4d37>     654
   mDNSResponder <820560222d47a1f2a0dce98a7f8a9721>     112
    mediaserverd <ea8bac28b06fe3980fdd44b5caceb563>    5931
       lockdownd <497fd54c79a680bf29f5d9320f514613>     579
MobileStorageMou <c277b79c2157c4dc5cfc5c3ca35bd5f2>      76
         syslogd <66247e305d5c0bf6f1ce1cc950653263>      80
            ptpd <83de0f774bd6553d513ae9e19b0f9b56>     233
         launchd <66972eee4d865c4383b33d985d22994b>      72

**End**
Tue Aug 10 15:12:05 hokudaiaoniaowangruande-iPad SpringBoard[26] <Warning>: Received memory warning. Level=1
Tue Aug 10 15:12:05 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: Received memory warning. Level=1
Tue Aug 10 15:12:20 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:12:32 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:12:32 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:12:37 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:13:28 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:13:28 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:13:44 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:14:11 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:14:11 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:14:20 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:14:50 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:14:50 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:14:56 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:15:02 hokudaiaoniaowangruande-iPad mDNSResponder[19] <Error>: ERROR: mDNSPlatformReadTCP - recv: 60 (Operation timed out)
Tue Aug 10 15:16:11 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:16:11 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:17:33 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:17:44 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:17:44 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:18:01 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:18:07 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:18:07 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:18:07 hokudaiaoniaowangruande-iPad configd[24] <Notice>: jetsam: kernel memory event (90), free: 695, active: 1734, inactive: 985, purgeable: 3456, wired: 18656
Tue Aug 10 15:18:07 hokudaiaoniaowangruande-iPad SpringBoard[26] <Warning>: Received memory warning. Level=2
Tue Aug 10 15:18:07 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: Received memory warning. Level=2
Tue Aug 10 15:18:07 hokudaiaoniaowangruande-iPad SpringBoard[26] <Warning>: Memory level is urgent (10%) and there are no background apps to ask to exit.
Tue Aug 10 15:19:07 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:19:15 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:19:15 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:20:02 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:20:06 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:20:06 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:21:01 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:21:06 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playable
Tue Aug 10 15:21:06 hokudaiaoniaowangruande-iPad iPad4HB[107] <Warning>: playing
Tue Aug 10 15:21:24 hokudaiaoniaowangruande-iPad configd[24] <Notice>: jetsam: kernel termination snapshot being created
Tue Aug 10 15:21:24 hokudaiaoniaowangruande-iPad com.apple.launchd[1] (UIKitApplication:com.yourcompany.iPad4HB[0x4df4][107]) <Notice>: (UIKitApplication:com.yourcompany.iPad4HB[0x4df4]) Bug: launchd_core_logic.c:3232 (24063):0
Tue Aug 10 15:21:24 hokudaiaoniaowangruande-iPad com.apple.launchd[1] (UIKitApplication:com.yourcompany.iPad4HB[0x4df4][107]) <Notice>: (UIKitApplication:com.yourcompany.iPad4HB[0x4df4]) Bug: launchd_core_logic.c:3309 (24063):0
Tue Aug 10 15:21:24 hokudaiaoniaowangruande-iPad com.apple.debugserver-44[106] <Warning>: 1 [006a/1703]: error: ::read ( 6, 0x2809f4, 1024 ) => -1 err = Bad file descriptor (0x00000009)
Tue Aug 10 15:21:24 hokudaiaoniaowangruande-iPad com.apple.launchd[1] (UIKitApplication:com.yourcompany.iPad4HB[0x4df4][107]) <Notice>: (UIKitApplication:com.yourcompany.iPad4HB[0x4df4]) Bug: launchd_core_logic.c:2650 (24063):10
Tue Aug 10 15:21:24 hokudaiaoniaowangruande-iPad com.apple.launchd[1] (UIKitApplication:com.yourcompany.iPad4HB[0x4df4][107]) <Notice>: (UIKitApplication:com.yourcompany.iPad4HB[0x4df4]) Working around 5020256. Assuming the job crashed.

6 个答案:

答案 0 :(得分:4)

我认为它确切地告诉你问题是什么:你使用了太多的内存。如果操作系统告诉你这个并且你什么都不做,那么它(实际上)可能会从内存中弹出你的程序。

您不发布任何代码,因此不清楚您是否有内存泄漏或只是使用了太多内存。尝试使用静态分析器(在Xcode的构建菜单中)和仪器的泄漏部分来检查泄漏。如果它没有找到,那么你可能只需要优化你的应用程序以减少内存使用。

我不确定你在哪里发现36Mb没问题。在第一代设备上,你将被释放出超过20Mb的内存。我不认为有任何绝对数字记录,所以你需要做两件事:在真实设备上测试并在它告诉你使用太多时尽可能多地释放内存。

答案 1 :(得分:3)

似乎是内存泄漏。要找到它,不仅要使用“Leaks”仪器。 “分配”也可以帮到你。主动使用它,标记堆,比较内存使用情况并检查“仍然存活”的对象(尤其是您自己类的对象)。

有时无法自动检测到内存泄漏(使用“Leaks”Instrument)。例如,假设您有一些UIImageView。当用户触摸“创建”按钮时,应创建此图像视图,并在触摸“销毁”按钮时销毁。您可以像下面的代码一样实现此行为:

- (IBAction)bCreateTouchUpInside:(id)sender {
    ivSomeImageView = [[UIImageView alloc] initWithImage:iSomeImage];
    [self.view addSubview:ivSomeImageView];
    bCreate.enabled = NO;   bDestroy.enabled = YES;
}

- (IBAction)bDestroyTouchUpInside:(id)sender {
    [ivSomeImageView release];
    bCreate.enabled = YES;   bDestroy.enabled = NO;
}

并且会出现内存泄漏:保留两次(creation + addSubview),一次性释放(release)。要解决此问题,您应在直接发布消息之前添加[ivSomeImageView removeFromSuperview];。但是“泄漏”仪器不会检测到这种泄漏,因为有一个指向图像视图的正确指针(父视图存储指向它的子视图的指针)。唯一有机会为您检测此泄漏的方法是多次按“创建”并查看每次内存使用量的增加。

答案 2 :(得分:2)

您是否尝试在很短的时间内加载大量数据?尝试运行图像视图动画序列时尤其如此。当内存小于20MB时我崩溃了。经过调查,我发现我的图像序列包含非常大的图像,崩溃的原因不是总内存负载。原因是内存带宽。

答案 3 :(得分:1)

如果你使用的是比较2g或3g的旧型号,36 megs可能比你玩的更多。我通常会在25mb左右开始收到警告。

答案 4 :(得分:1)

手机内存不足时,会收到内存警告。 “1级”内存警告非常正常。如果你的应用程序崩溃了,那可能是因为你没有正确处理内存警告而不是因为你使用了太多内存。有两个修复:

  • 忽略内存警告(不要在didReceiveMemoryWarning中超级调用)
  • 修复您的代码

答案 5 :(得分:1)

我在最近的项目中遇到过类似的问题。对我来说,这个问题隐藏在一个隐藏在委托属性上的隐藏语句中,该语句保留了保留计数,导致视图无法成功解除分配。

尝试这种故障排除技术..... 大概你可能有一个uinavigation控制器推/弹视图控制器。

考虑到视图中存在保留计数导致视图保留在内存中的某些内容(即使视图已弹出并且您已发出release语句)。另一个症状(不是特定于此问题,但相关的是如果弹出所有视图控制器,您甚至可能遇到应用程序崩溃。)

所以在视图控制器的dealloc方法中  对相应视图的保留计数执行日志声明。 (和你正在合成的其他物体。) 例如。

UiNavController

-Level0ViewController
        -(void)dealloc{
         // HERE TEST FOR RETAIN COUNT OF 2  (2 = one for the alloc / one for the addSubview)
         DLog(@"level0view  retain count: :%@",[level0view retainCount]);
         [level0view release]; // this will make retain count 1.
         [super dealloc];
  -- Level0View
     -(void)dealloc{
        DLog(@"dealloc"); // set break points here and confirm this is being called.
     }
   -- SomeImageView.h
      // for me my problem lied here with the infringing line below being RETAIN! it should  have been assign. changing this successfully resolved app crash and memory leak. 
      @property(retain) id delegate

P.S。查看由Karl Kroft编写的DLog - 记录非常好,为您提供类的行号并隐藏NSLog通常添加的guff。