In Cocoa (and other frameworks that derive from NeXTSTEP), dealloc is the instance method responsible for tearing down an object. It should release the object's references to its ivars and then call up to the superclass's implementation.
Questions tagged [dealloc]
497 questions
3
votes
1 answer
iphone: -[CFString release]: message sent to deallocated instance
an app I'm working on keeps crashing when run on the iPhone but not on the Simulator (although a warning is shown when run without symbolic malloc_error_break, but the app keeps working on the Sim)
I'm not manually releasing any string, instead, i…

David Homes
- 2,725
- 8
- 33
- 53
3
votes
2 answers
Best practice for adding/removing observers to/from NSNotificationCenter
What's the best practice for adding and removing observers to/from NSNotificationCenter?
I'm wondering if adding self as an observer in viewDidLoad and removing self in viewDidUnload is sufficient. Or perhaps I should remove self in dealloc as…

SundayMonday
- 19,147
- 29
- 100
- 154
3
votes
1 answer
Removing Observer in Dealloc
SOLVED - it turns out that passing nil to removeObserver:forKeyPath: fails, but ONLY in manual memory management. It works fine in garbage collected mode. The Apple documentation does NOT say it requires a non-nil value so I'm assuming it's a…

jstm88
- 3,335
- 4
- 38
- 55
3
votes
3 answers
Objective-c dealloc of boolean value
How would I dealloc a boolean value?
Deallocing it this way below gives me a warning: Incompatible pointer to integer conversion assigning to 'BOOL' (aka 'signed char') from 'void *'
- (void)dealloc {
self.booleanVar = nil;
[super…

Peter Warbo
- 11,136
- 14
- 98
- 193
3
votes
1 answer
When does (void)dealloc get called in an AppDelegate?
I understand that instance variables are released in dealloc (as shown below), but when exactly is it called? Are all instance variables released upon app close, or is there an accepted way for them to be deallocated individually as they become…

Old McStopher
- 6,295
- 10
- 60
- 89
3
votes
2 answers
How to make sure your dealloc code is called on application termination?
According to NSObject's 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…

cfischer
- 24,452
- 37
- 131
- 214
3
votes
1 answer
Invalidating an NSTimer in dealloc
Following this question, and more specifically, this comment:
because retain (aka strong reference) cycles in the common case where the timer's target is also its owner
I am wondering why dealloc isn't a good place to invalidate an NSTimer.
I…

Iulian Onofrei
- 9,188
- 10
- 67
- 113
3
votes
1 answer
Strong references and UIView memory issues
I'm dealing with some deallocation issue and perhaps strong or circular referencing that can't figure out. I have three UIViews instantiating like below:
There is one main ViewController which I have added a UIView inside it in storyboard and the…

TheBen
- 3,410
- 3
- 26
- 51
3
votes
4 answers
iPhone EXC_BAD_ACCESS when calling [super dealloc] on a custom UIViewController
I'm at a loss! It's one of those pesky bugs that happens only under specific conditions, yet I cannot link the conditions and the results directly.
My app has a paged UIScrollView where each page's view comes from a MyViewController, a subclass of…

SaltyNuts
- 5,068
- 8
- 48
- 80
3
votes
2 answers
UINavigationController and UIViewController dealloc
I recently changed my app to use a UINavigationController, I was using a UINavigationBar before, with cascade subView adding, which was a bit tenuous.
I'm facing a problem of memory usage. Leaks tool doesn't show any leak, but ViewControllers I…

Jukurrpa
- 4,038
- 7
- 43
- 73
3
votes
0 answers
memory dealloc general xcode swift information
Im fairly new to iOS swift development and Im having issue understanding the memory management.
the app Im working on is a chain of table views ending with a AVPlayerView Controller playing videos from streaming urls.
When running the app in the…

SKYnine
- 2,708
- 7
- 31
- 41
3
votes
1 answer
reallocating memory of a vector
I am using vector > ar[100000];
and I have to use it for several test cases where every time I want it to initialize but I am getting segmentation fault for this.
I tried it with declaring inside the test case loop and globally. its…

whishky
- 396
- 3
- 13
3
votes
1 answer
AVPlayerItem addobserver issue in iOS8
Hi I am playing video on my UITableViewCells using AVPlayer, It was working fine on iOS 7, but in iOS8 it crashing with following error.
'An instance 0x7c01b000 of class AVPlayerItem was deallocated while key value observers were still…

NITHIN SHAHRUKH
- 155
- 1
- 3
- 10
3
votes
1 answer
Destroy object in background thread Objective C
I have a absolutely huge array (~10 million objects which themselves hold substantial data). Destroying this object causes a quite long lag on the main thread of roughly 5 seconds. While this is just a test case for huge data I'd like to be able to…

utahwithak
- 6,235
- 2
- 40
- 62
3
votes
1 answer
Dealloc not called on all view controllers when using unwind segues
I am designing a game with 6 view controllers.
I use modal segues to navigate forward and unwind segues to navigate back.
The game flow through the view controllers is A -> B -> C -> D -> E -> F.
When I try to unwind from F to A dealloc is only…

user1980555
- 53
- 8