简体   繁体   English

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

[英]why did my app just used about 36MB memory but i still receive low memory warning?

i use instruments to track my app's usage of memory,in memory monitor,i find that real memory is below 36MB ,and most time it just 32MB,but i still get warnings low memory in organizer and crashed. 我使用仪器来跟踪我的应用程序的内存使用情况,在内存监视器中,我发现实际内存低于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.

I think it's telling you exactly what the problem is: you're using too much memory. 我认为它确切地告诉你问题是什么:你使用了太多的内存。 If the OS tells you this and you do nothing about it then it may (indeed, does) eject your program from memory. 如果操作系统告诉你这个并且你什么都不做,那么它(实际上)可能会从内存中弹出你的程序。

You don't post any code so it's not clear whether you have a memory leak or are just using too much memory. 您不发布任何代码,因此不清楚您是否有内存泄漏或只是使用了太多内存。 Try using the static analyser (in the build menu of Xcode) and the Leaks part of Instruments to check for leaks. 尝试使用静态分析器(在Xcode的构建菜单中)和仪器的泄漏部分来检查泄漏。 If it doesn't find any then you may just have to optimise your app to use less memory. 如果它没有找到任何,那么你可能只需要优化你的应用程序以减少内存使用。

I'm not sure where you found that 36Mb is okay. 我不确定你在哪里发现36Mb还可以。 On first gen devices you'll get kicked out of memory much above 20Mb. 在第一代设备上,你将被释放出超过20Mb的内存。 I don't think there's any absolute number documented, so you need to do two things: test on real devices and release as much memory as possible when it tells you that you're using too much. 我不认为有任何绝对数字记录,所以你需要做两件事:在真实设备上测试并在它告诉你使用太多时尽可能多地释放内存。

Seems to be a memory leak. 似乎是内存泄漏。 To find it, use not only "Leaks" Instrument. 要找到它,不仅要使用“Leaks”仪器。 "Allocations" also can help you. “分配”也可以帮到你。 Use it actively, mark heaps, compare memory usage and examine "still alive" objects (especially objects of your own classes). 主动使用它,标记堆,比较内存使用情况并检查“仍然存活”的对象(尤其是您自己类的对象)。

Sometimes memory leaks can't be automatically detected (with "Leaks" Instrument). 有时无法自动检测到内存泄漏(使用“Leaks”Instrument)。 For example, imagine that you have some UIImageView. 例如,假设您有一些UIImageView。 This image view should be created, when user touches "Create" button, and destroyed, when he touches "Destroy" button. 当用户触摸“创建”按钮时,应创建此图像视图,并在触摸“销毁”按钮时销毁。 You can implement this behavior like in code below: 您可以像下面的代码中那样实现此行为:

- (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;
}

And there will be a memory leak: two-times retained (creation + addSubview), one-time released (release). 并且会有内存泄漏:保留两次(creation + addSubview),一次性释放(release)。 To solve the problem, you should add [ivSomeImageView removeFromSuperview]; 要解决这个问题,你应该添加[ivSomeImageView removeFromSuperview]; before direct release message. 在直接发布消息之前。 But this leak won't be detected by "Leaks" Instrument, cause there is a correct pointer to your image view (parent view stores pointers to it's subviews). 但是“泄漏”仪器不会检测到这种泄漏,因为有一个指向图像视图的正确指针(父视图存储指向它的子视图的指针)。 And the only chance to detect this leak for you is to press "Create" for numerous times and to see that memory usage increases each time. 并且唯一一次为您检测此泄漏的机会是多次按“创建”并查看每次内存使用量增加。

Are you trying to load huge amount of data in a very short time? 您是否尝试在很短的时间内加载大量数据? This is specially the case when trying to run an image view animation sequence. 尝试运行图像视图动画序列时尤其如此。 I got a crash when the memory was less than 20MB. 当内存小于20MB时我崩溃了。 After investigation I found that my image sequence contained very big images and the reason of crash was not total memory load. 经过调查,我发现我的图像序列包含非常大的图像,崩溃的原因不是总内存负载。 The reason was memory bandwidth. 原因是内存带宽。

If you're on an older model like a 2g or 3g, 36 megs is probably more ram than you've got to play with. 如果你使用的是比较2g或3g的旧型号,那么36 megs可能比你玩的更多。 I usually start getting warnings around 25mb. 我通常会开始收到大约25mb的警告。

You get memory warnings when phone memory is low. 手机内存不足时会收到内存警告。 "Level 1" memory warnings are pretty normal. “1级”内存警告非常正常。 If your app is crashing, then it's probably because you're not handling the memory warning properly rather than because you're using too much memory. 如果你的应用程序崩溃了,那可能是因为你没有正确处理内存警告而不是因为你使用了太多内存。 There are two fixes: 有两个修复:

  • Ignore the memory warning (don't super-call in didReceiveMemoryWarning) 忽略内存警告(不要在didReceiveMemoryWarning中超级调用)
  • Fix your code 修复你的代码

I experienced a similar problem in latest project. 我在最近的项目中遇到了类似的问题。 For me the problem lied buried in an obscure retain statement on a delegate property that was holding onto the retain count causing the view to not successfully deallocate. 对我来说,这个问题掩盖在一个隐藏在委托属性上的一个隐晦的保留语句中,该委托属性持有保留计数导致视图无法成功解除分配。

Try this troubleshooting technique..... presumably you may have a uinavigation controller pushing / popping view controllers. 尝试这种故障排除技术.....大概你可能有一个uinavigation控制器推/弹视图控制器。

Consider that there is something in the view holding the retain count causing the view to stay in memory(even though view has popped and you've issued the release statement). 考虑到视图中存在保留计数导致视图保留在内存中的某些内容(即使视图已弹出并且您已发出release语句)。 Another symptom (not specific to this problem but related is if do a pop all view controllers, you may even be experiencing an app crash. ) 另一个症状(不是特定于此问题,但相关的是如果弹出所有视图控制器,您甚至可能遇到应用程序崩溃。)

So in the dealloc methods of view controller(s) do a log statement on the retain count of the respective view. 因此,在视图控制器的dealloc方法中,对相应视图的保留计数执行日志语句。 (and other objects you're synthezing. ) eg. (和你正在合成的其他物体。)例如。

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

PS check out the DLog by Karl Kroft - that logging is very nice giving you the the line number of class and hiding the guff that NSLog usually adds. PS检查了Karl Kroft的DLog - 记录非常好,为您提供类的行号并隐藏NSLog通常添加的guff。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM