简体   繁体   中英

iOS app dealloc on home button press

I'm not using ARC and am a bit confused about what happens to all the objects I've retained when an app becomes suspended.

I had a look at this thread but it didn't help that much:

iPhone. Shouldn't hitting the home button cause UIApplicationDelegate's dealloc to be called

I've read the apple docs on multitasking but couldn't find any information specifically about dealloc.

I ran instruments, which didn't find any leaks but I'm unclear on what happens when the stop button is pressed

So my questions are:

1) Why aren't some of my dealloc methods being called? For example, the dealloc for my UIResponder is not being called (when I double tap the home button on my iPad and remove my app) and neither are the ones for any of my UIViewController objects.

2) When I hit the stop button on Instruments (while it's running checking for leaks), what mode is the app placed in? (for eg inactive, background, suspended....something else?)

Since my mind is too accustomed to the C++ way of thinking where an application exit results in destructors being called, it's hard for me to visualise the iOS equivalent.

iOS deployment target: 8.0

  1. Your app is simply sent to the background. It's still in memory. If the user brings your app back up, it's right where it left off. It would be bad if anything was deallocated for no reason just because it wasn't in the foreground. When a user double-taps the Home button and removes the app, the app is killed hard. See #2.
  2. When you hit the Stop button in Xcode (or the user terminates the app by double-pressing the Home button) your app is killed. The app process is gone. All memory and other resources are released. This is the sledgehammer. Your app is terminated with no notification of any kind. Imagine doing kill -9 from the command line.

None of this has anything to do with using ARC or not. None of it has to do with using Objective-C or C++ or Swift.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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