Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

something about the dealloc method

Suppose I have a root controller MyViewController, with an instance variable named var1. I assign a value to var1, yet I don't release it in dealloc method.

My question is what is it going to happen after the app exit?

like image 650
Carusd Ray Avatar asked Aug 12 '11 04:08

Carusd Ray


People also ask

What does dealloc do?

The DEALLOC operation frees one previous allocation of heap storage. pointer-name is a pointer that must be the value previously set by a heap-storage allocation operation (either an ALLOC operation in RPG, or some other heap-storage allocation mechanism).

What is Dealloc in Objective C?

It's called when the reference count for that object becomes 0 because all its pointers have been released. The memory taken up by it is deallocated (freed); the object itself is destroyed.

What is Dealloc in C?

-dealloc is an Objective-C selector that is sent by the Objective-C runtime to an object when the object is no longer owned by any part of the application. -release is the selector you send to an object to indicate that you are relinquishing ownership of that object.

Can we implement Dealloc in ARC?

Ans is NO Because with ARC no need to dealloc.


2 Answers

From dealloc documentation...

Important: Note that when an application terminates, objects may not be sent a dealloc message since the process’s memory is automatically cleared on exit—it is more efficient simply to allow the operating system to clean up resources than to invoke all the memory management methods. For this and other reasons, you should not manage scarce resources in dealloc—see “Object Ownership and Disposal” in Memory Management Programming Guide for more details.

like image 171
Krishnabhadra Avatar answered Oct 12 '22 08:10

Krishnabhadra


The memory is reclaimed when the app exits. However, keep in mind your app is not exiting in recent versions of iOS unless the user terminates it or the OS terminates it for using too much memory.

like image 20
Nathanial Woolls Avatar answered Oct 12 '22 08:10

Nathanial Woolls