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
209
votes
1 answer

Custom dealloc and ARC (Objective-C)

In my little iPad app I have a "switch language" function that uses an observer. Every view controller registers itself with my observer during its viewDidLoad:. - (void)viewDidLoad { [super viewDidLoad]; [observer…
Niku
  • 2,099
  • 2
  • 12
  • 4
145
votes
6 answers

dealloc in Swift

I would like to perform some cleanup at the end of a view controller's life, namely to remove an NSNotificationCenter notification. Implementing dealloc results in a Swift compiler error: Cannot override 'dealloc' which has been marked…
Kyle Clegg
  • 36,212
  • 26
  • 127
  • 138
24
votes
5 answers

iPhone - dealloc - Release vs. nil

Wondering if someone with experience could possibly explain this a bit more. I have seen examples of... [view release]; view = nil; ....inside the (void) dealloc. What is the difference and is one better then the other? What is the best…
bbullis21
  • 741
  • 3
  • 9
  • 21
24
votes
2 answers

Valid use of accessors in init and dealloc methods?

I've heard now from several sources (stackoverflow.com, cocoa-dev, the documentation, blogs, etc) that it is "wrong" to use accessors and settings (foo, setFoo:) in your init and dealloc methods. I understand that there is there is a remote…
Dave DeLong
  • 239,073
  • 58
  • 443
  • 495
23
votes
1 answer

Why setting object that is undergoing deallocation to weak property results in crash

In Clang's Objective-C Automatic Reference Counting we see the following For __weak objects, the lvalue is updated to point to the new pointee, unless the new pointee is an object currently undergoing deallocation, in which case the lvalue is…
22
votes
1 answer

Initializing a property, dot notation

Is it a bad idea to use the dot notation to initialize retain properties to nil in my init methods? With any ordinary property like this: @property (nonatomic, retain) id foo; Say in my init method I set self.foo = nil. The synthesized method…
19
votes
2 answers

UIPopoverController dealloc getting called—ARC environment

While displaying a popover controller for a second time (after dismissing it and then re-displaying it), I get the following error: Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while…
18
votes
5 answers

Adding and removing observers to NSNotificationCenter in a UIViewController

Looking at various Apple examples (for example Add Music) in which I see they add observers to the default NSNotificationCenter in viewDidLoad, then remove them in dealloc. This seems dangerous as viewDidLoad can be called multiple times without…
Undistraction
  • 38,727
  • 46
  • 165
  • 296
17
votes
1 answer

If a function returns an UnsafeMutablePointer is it our responsibility to destroy and dealloc?

For example if I were to write this code: var t = time_t() time(&t) let x = localtime(&t) // returns UnsafeMutablePointer println("\(x.memory.tm_hour): \(x.memory.tm_min): \(x.memory.tm_sec)") ...would it also be necessary to also do…
sketchyTech
  • 5,137
  • 28
  • 52
14
votes
4 answers

Who calls the dealloc method and when in Objective C?

When a custom class is created in Objective C, when and how is the dealloc method called? Is it something that I have to implement somehow in my class?
Sujal
  • 1,205
  • 11
  • 24
14
votes
14 answers

Force explicit deletion of a Java object

I'm working on a Java server that handles a LOT of very dense traffic. The server accepts packets from clients (often many megabytes) and forwards them to other clients. The server never explicitly stores any of the incoming/outgoing packets. Yet…
Curious George
  • 143
  • 1
  • 1
  • 5
14
votes
2 answers

Printing Instance ID to NSLog?

In the dealloc method for a class how would I print out the ID (or some other unique identifier) for the instance being deallocated? - (void)dealloc { NSLog(@"_deallocing: ??"); [super dealloc]; } Is this possible? I am just trying to get…
fuzzygoat
  • 25,797
  • 45
  • 159
  • 288
13
votes
2 answers

Correct [super dealloc]

Does the order of statements in the dealloc method matter? Does the [super dealloc] need to be at the top of the method? Does it matter? Also in e.g. viewDidLoad. Should [super viewDidLoad] be at the top of the method?
some_id
  • 28,294
  • 58
  • 173
  • 293
13
votes
3 answers

Crash on EXC_Breakpoint Scroll View

This is a new problem I have been having ever since I've been updating my app for iOS 7. Everytime I launch the app on my device or simulator, I get this error code RecipeDetailViewController scrollViewDidScroll:]: message sent to deallocated…
user331914
12
votes
2 answers

dismissViewControllerAnimated does not deallocate viewcontroller

First off: My project is ARC enabled and I'm using storyboard. I have a view controller that pushes a segue (modal), [self performSegueWithIdentifier: @"goInitialSettings" sender: self]; there i'm setting some parameters and store them. When the…
1
2 3
33 34