Objective-C garbage collecting

Garbage collecting is the process of freeing up system memory automatically so you, the programmer, don’t have to manually dump the memory from file. It can be turned on and is a great asset when programming with Objective-C.

Advantages of the garbage collector

The garbage collector, also known as “GC,” can actually increase the speed of programs as opposed to manually freeing up memory. This is because the garbage collector can take advantage of idle processors on your chip running in the background and not affecting your programs speed.

Requirements

Garbage Collector is only available on operating systems released after Snow Leopard 1.5, it is also not available when programming for the Ipod Touch or IPhone.

Enabling the Garbage Collector

In order to enable Garbage Collector you will need to open a new Xcode application if you have not done so already. Go to the top of the screen where you will see the menu item “Project,” now go down to “edit project settings.”

Once the window pops up you are going to need to click the build tab at the top then scroll down the list until you reach a heading on the left side entitled “GCC 4.2 – Code Generation” on Snow Leopard or “GCC 4.0 Code Generation.” Go down the list in this section to where it says “Objective-C Garbage Collection.” To the right of that setting it should be defaulted at “Unsupported” change this to “[-fobjc-gc]”

Now you have successfully enabled garbage collecting. This should be used with the new Macs since they have multiple cores. If you would like to manage memory manually you can go ahead and skip this article.