3

I found that the iphone have viewDidUnload, and dealloc. I want to release the object. Which method should I use to release the object? What's the different between them?

Tattat
  • 15,548
  • 33
  • 87
  • 138
  • I don't know Objective-C or iPhone development, but viewDidUnload does not sound like a method that is used to release an object. – OregonGhost Feb 25 '10 at 14:34

3 Answers3

7

Send release or autorelease to release an object. You shouldn't send dealloc; the Obj-C runtime will do that.

If you're asking where you should release an owned object, read: "When should I release objects in -(void)viewDidUnload rather than in -dealloc?"

Community
  • 1
  • 1
outis
  • 75,655
  • 22
  • 151
  • 221
0

Do not call dealloc. Use the retain-release model for memory management, and Objective-C will take care of deallocating memory for you.

See this link for a good explanation of how retain-release works.

Aaron
  • 6,988
  • 4
  • 31
  • 48
0

The difference is that viewDidUnload is used to release "spare" objects in low memory situations while dealloc is used to release all objects when the view is no longer needed.

This means that you will almost always have a dealloc method but have a viewDidUnload method only where it makes sense.

Stephen Darlington
  • 51,577
  • 12
  • 107
  • 152