Questions tagged [dealloc]

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.

496 questions
11
votes
1 answer

Properly dealloc NSOperationQueue

I'd like to know what is the proper way to dealloc an ivar NSOperationQueue in case it has still some operations running, which can typically occur when the user suddenly quits the app. In some examples I saw the waitUntilAllOperationsAreFinished…
Tomas Camin
  • 9,772
  • 2
  • 39
  • 61
11
votes
6 answers

What is your preferred coding style for dealloc in Objective-C?

I know that discussions about coding styles tend to end in disaster and endless flame wars, but that’s not what I want to reach. During the last decade I mainly saw two different coding styles for dealloc methods in Objective-C. The first and most…
Rafael Bugajewski
  • 1,588
  • 3
  • 20
  • 36
11
votes
2 answers

Objective C - Where do you dealloc global static variables?

Or, what is the opposite of +(void)initialize? Here's my situation: I have a class Unit, whose -(id)initWithName: function takes data from a global NSDictionary, which is created lazily, defined in the Unit.m file as: static NSMutableDictionary…
abtree
  • 315
  • 4
  • 10
10
votes
4 answers

Dealloc method in iOS and setting objects to nil

I have a pretty basic question. In some examples I've seen, objects are just released in the dealloc method. In others, the objects are released and then set to nil. Is there a reason for this? Is setting to nil after releasing advantageous?
Mason
  • 6,345
  • 15
  • 67
  • 113
10
votes
1 answer

iOS: How can I destroy a Singleton in ARC? Should I?

I have a singleton class that accumulates data until that data is written to my database (if you want to know why I'm implementing things this way, see here). After saving the data, I would like to destroy the singleton. How can I do this in ARC? Or…
cmac
  • 896
  • 10
  • 18
9
votes
3 answers

NSTimer disables dealloc in UIView

@interface someview:UIView{ NSTimer* timer; } @end @implementation someview -(void)dealloc{ NSLog(@"dealloc someview"); [timer invalidate]; timer = nil; } -(void)runTimer{ // } -(void)someMethod{ timer = [NSTimer…
ssj
  • 871
  • 1
  • 10
  • 21
9
votes
1 answer

Is there any problem using self.property = nil in dealloc?

I know declared property generates accessor method which is someway just syntax sugar. I found quite a lot people use self.property = nil in their dealloc method. 1) In Apple's Memory Management document, p23 It says: The only places you shouldn’t…
Jimmy
  • 1,094
  • 10
  • 21
8
votes
1 answer

Setting delegate to nil in dealloc

In Objective-C, I understand that if an object sets itself as the delegate of another object, it should set that object's delegate to nil in its dealloc to avoid getting sent messages after it's gone. However, when using Accessorizer (an Xcode…
jrdioko
  • 28,317
  • 26
  • 75
  • 116
8
votes
4 answers

Locationservice Indicator stays "on"

I have a created a small app which uses location services on the iPhone. All works well, except the fact, that sometimes, the small arrow in the info-bar stays active even if I explicitly kill the app. I use the background mode for…
Axel
  • 1,646
  • 1
  • 16
  • 28
8
votes
1 answer

deleteRowsAtIndexPaths: swipe to delete rows never deallocates the cell?

I'm wondering if I've somehow stumbled upon a bug where swipe to delete UITableViewCells don't ever deallocate when their UITableViewController does. I've added a -dealloc method into my custom table cell, which logs out a message. When I press back…
derbs
  • 133
  • 1
  • 5
8
votes
2 answers

Should -dealloc do anything other than release memory?

I inherited an iPhone app at work and I'm new to Objective-C so I don't have my bearings just yet. I encountered code similar to this: - (void) dealloc { [[StaticObject sharedObject] showSomeDialog]; [super dealloc]; } I know this is…
ageektrapped
  • 14,132
  • 7
  • 54
  • 70
8
votes
1 answer

Crashlytics: "Crashed: NSOperationQueue 0x... :: NSOperation 0x..." - EXC_BAD_ACCESS KERN_INVALID_ADDRESS

I got some crash reports in crashlytics which I don't understand at all, here's the crash log of the thread that crashed: I don't find any hints to my code, nor is it something reproducable or only happening on specific devices. According to…
swalkner
  • 15,150
  • 25
  • 107
  • 195
8
votes
5 answers

How can I reference __weak self in dealloc method

I have a method called in various places called "cancelAllPendingDownloads" This is a general method that cancels various jobs and updates internal counters. Problem happens when it is called within the dealloc method -(void)dealloc { [self…
Avner Barr
  • 13,049
  • 14
  • 82
  • 152
8
votes
3 answers

Can garbage Collector deallocate singleton instance? (and why or how to avoid it)

In Android I have singleton class but I am not sure if the garbage Collector can deallocate it. If garbage Collector will deallocate my singleton class how can avoid it from deallocation?
Rooban Ponraj A
  • 281
  • 4
  • 19
8
votes
3 answers

View controller dealloc not called when using NSNotificationCenter code block method with ARC

When I use -addObserverForName: object: queue: usingBlock: for NSNotificationCenter in the -viewDidLoad: method of my view controller, the -dealloc method ends up not being called. (When I remove -addObserverForName: object: queue: usingBlock:,…
James
  • 762
  • 7
  • 22
1
2
3
33 34