views:

508

answers:

4

Hi I just picked up Obj-C and quite dislike its manual memory management.

I decide to go with its Garbage Collection, by adding

objc_startCollectorThread();//garbage collection

in my Main() and change the garbage collection value to [-fobjc-gc]

So is that all I need? So I can program "freely" like I do in Java/Python..etc?

A: 

Basically, yes. This is covered in Apple's documentation. You may also need occasional calls to

objc_clear_stack

But this is optional, to ensure stack retained object lifetimes are as short as needed.

Adam Wright
+4  A: 

Yes you are right, but in case any iPhone programmer comes by and thinks "oh sweet!", please note that the iPhone doesn't support Garbage Collection yet (ever?). So this is the MacOS only solution.

Robert Gould
wow. thanks for telling me that --- as I was actually addressing the iPhone platform
ivanTheTerrible
I kind of guessed that. Objective-C almosts equals iPhone for most people :)
Robert Gould
+2  A: 

Note that -fobjc-gc means that you still use retain/release (when writing a Framework/library); you probably want -fobjc-gc-only if you want to get rid of the reference counting code completely.

Jesse Rusak
+2  A: 

As other said, there is no garbage collection in iPhone.

If you are writing a Desktop Cocoa app, all you need is the -fobjc-gc-only flag, without the explicit objc_startCollectorThread() startup function.

mouviciel