iOS 开发实用技术导航
NSHipster 中文版
› http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
› http://www.cocos2d-iphone.org/
CocoaPods
› http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
› http://code.google.com/mobile/analytics/
WWDC
› https://developer.apple.com/wwdc/
Design Guides and Resources
› https://developer.apple.com/design/
Transcripts of WWDC sessions
› http://asciiwwdc.com
Cocoa with Love
› http://cocoawithlove.com/
Cocoa Dev Central
› http://cocoadevcentral.com/
NSHipster
› http://nshipster.com/
Style Guides
› Google Objective-C Style Guide
› NYTimes Objective-C Style Guide
Useful Tools and Services
› Charles Web Debugging Proxy
› Smore
tedd
V2EX  ›  iDev

新手问题,一个 array 在 app 中的生命周期

  •  
  •   tedd · Apr 3, 2014 · 2788 views
    This topic created in 4560 days ago, the information mentioned may be changed or developed.
    如果我在AppDelegate中的appDidFinishedLauching里面声明了一个array,app第一次被运行时候被分配,是否只要在这个app不彻底从系统中退出(双击home键将这个app卡片划出去),那这个array就一直在,且保存着其中的数据呢?
    3 replies  •  1970-01-01 08:00:00 +08:00
    dorentus
        1
    dorentus  
       Apr 3, 2014
    假如这个 array 被赋为了某个持久对象(比如 AppDelegate 的实例)的 strong 属性,那么是。
    否则的话,出了作用域这个 array 就没了……
    dorentus
        2
    dorentus  
       Apr 3, 2014
    @dorentus 补充一下,上面这个是开启 ARC 的情况。array 没了是因为编译器自动在出作用域之前给它发了 release 消息。

    没开启 ARC 的话(现在已经很少有人这么做了吧),除非手动发 release 消息直至 retain count 为 0,否则 alloc 过的对象一直存在。
    Him
        3
    Him  
       Apr 4, 2014
    app在启动的时候会创建一个autoreleasepool(见main),如果array并不是alloc、new出来的,可以自动释放
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2584 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 11:20 · PVG 19:20 · LAX 04:20 · JFK 07:20
    ♥ Do have faith in what you're doing.