开发者

How to use finalize method in Objective-C?

How do I call the -finalize method in Objective-C for garbage c开发者_如何学Goollection?


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.


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


There is Automatic reference counting(ARC) which does the memory management on behalf of us.We don't have to use retain,release like this statements with objects it takes care of these things....

But there is no dedicated garbage collector which is like in c#.

Here is how it works:

when ARC is enabled the compiler adds retain,release,autolease like these statements by itself.

but if we were to use ARC then we can't release any object manually that is the only draw back of this approach..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜