iOS extracts: Observing low-memory warnings

--from 《iPhone Application Development For Dummies - Neal Goldstein》


Observing low-memory warnings

When the system dispatches a low-memory notification to your application, itis something you must pay attention to. If you don’t, it is a reliable recipe fordisaster. (Think of your low-fuel light going on as you approach a sign thatsays “Next services 100 miles.”) UIKit provides several ways of setting upyour application so that you receive timely low-memory notifications:

  • ✓  Implement theapplicationDidReceiveMemoryWarning:method ofyour application delegate. Your application delegate could then releaseany data structure or objects it owns — or notify the objects to releasememory they own.

  • ✓  Override thedidReceiveMemoryWarning:method in your customUIViewControllersubclass. The view controller could then releaseviews — or even other view controllers — that are off-screen.

    Register to receive theUIApplicationDidReceiveMemoryWarningNotification:notification. A model object could then release datastructures or objects it owns that it doesn’t need immediately and canre-create later. 


    Each of these strategies gives a different part of your application a chance tofree up the memory it no longer needs (or doesn’t need right now). As for howyou actually get these strategies working for you, while I will mention a strat-egy for implementing the view controller’sdidReceiveMemoryWarning:inChapter 14, this is something that is dependent on your application’s architec-ture. That means you’ll need to explore it on your own.

    Not freeing up enough memory will result in the iPhone’s OS sending yourapplication theapplicationWillTerminate:message and shutting youdown. For many applications, though, the best defense is a good offense,and you need to manage your memory effectively and eliminate any memoryleaks in your code. 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值