views:

90

answers:

2

How to call finalize method in Obj-c for garbage collection?

+8  A: 

iOS does not offer garbage collection:

In iOS, you always use the memory-managed model to retain, release, and autorelease objects. Garbage collection is not supported in iOS.

Alex Reynolds
A: 

As Alex Reynolds tells you, there actually is (and maybe there will never be) no garbage collection in iOS. Besides of that in the NextStep-object hierarchy (you know all the classes with NS in its names?) there is a method called dealloc (http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/dealloc). It can override it (and should do this if there is something) to clean up. For example you should release other objects hold by the instance.

But don’t miss “You never send a dealloc message directly”!

Greetings

Objective Interested Person