9

I am learning Xcode and objective c, but the book I am reading is using the older version (3.2) of Xcode. One chapter, which is completely dedicated to memory and leaks, says I need to turn on garbage collection through Project Settings > Build. However, I can't find the garbage collection setting. Has it been removed or am I just missing it?

jerry
  • 2,743
  • 9
  • 41
  • 61

6 Answers6

8

Xcode 4 still has Garbage Collection, all you do is go into your project (the top option in the navigation bar with the big xcode project icon). Select your target which should just be the name of your app with the application icon next to it. When you select that, along the top there is a bar with different options, such as summary, info, build settings etc. Hit "Build Settings" and type "garbage" in the search field. Then set garbage collection to required.

One very important note about GC is that it is officially deprecated as of Mac OS 10.8, which means you should be transitioning your code to ARC if possible because GC might not be around for much longer.

Update: See other answers for enabling GC in current versions of Xcode. As I stated above, you should be transitioning to ARC if you haven't already.

Lucas Derraugh
  • 6,929
  • 3
  • 27
  • 43
  • In Xcode 4.4 searching for Garbage returns nothing as the build setting is now user defined. See my Xcode 4.4 reply. – Jonathan Mitchell Sep 26 '12 at 11:21
  • @Jonathan Mitchell, right. Click "Add Build Setting" at the bottom, and add: GCC_ENABLE_OBJC_GC with possible values: { required, supported, unsupported } – Bobjt Feb 21 '13 at 23:55
  • Right now, if you looking for "garbage" in search field, ARC appear in search results. So, I think there is no garbage collection, ARC replaced it. – Dima Deplov Aug 11 '13 at 09:15
4

As of XCode 4.4 the garbage collection build flag is user defined (see the very end of the build settings list).

GCC_ENABLE_OBJC_GC supported

Valid build settings are:

  • unsupported: The application cannot load code that requires garbage collection. The loadable bundle cannot be loaded by an application that requires garbage collection.

  • supported: The application can load code that supports or requires garbage collection. The loadable bundle can be loaded by an application with any level of garbage-collection support.

  • required: The application can load only code that supports garbage collection. The loadable bundle can be loaded only by an application that supports garbage collection.

Jonathan Mitchell
  • 1,339
  • 12
  • 17
2

Garbage collection is very much fully supported in Xcode 4. Xcode 4, itself, is a GC'd application.

GC is also very much not available in iOS. If you are writing an iPhone/iPad app, you can't use GC.

bbum
  • 162,346
  • 23
  • 271
  • 359
  • thanks bbum! you are actually mentioned in the book I'm reading. – jerry Mar 29 '11 at 14:30
  • Cocoa Programming - A Quick-Start Guide for Developers by Daniel Steinberg (page 76). I hope one day I'm as good as you. – jerry Mar 30 '11 at 21:30
1

As of Xcode 4.3.3 the only setting available for parameter "Objective-C Garbage Collection" under section "Apple LLVM compiler 3.1 - language", Build Settings for your target app = "Unsupported"

dvkempen
  • 11
  • 1
1

That's a challenge but you might be able to get it done - here's a starting point to think about in relation to PDF generation:

iOS SDK - Programmatically generate a PDF file

If you can generally follow what is going on there, you might be OK.

Community
  • 1
  • 1
Kendall Helmstetter Gelner
  • 74,769
  • 26
  • 128
  • 150
  • OP tagged "mac" not "iOS" -- do you know if that link will still apply? – Richard Mar 29 '11 at 01:40
  • Basically, yes (although the PDF generation on the Mac is probably not broken in the way he mentioned). But the basic PDF generation classes are the same. Creating a xib might be a different procedure though as you can't use UIKit on the Mac. Sorry about missing the Mac tag. – Kendall Helmstetter Gelner Mar 29 '11 at 01:58
1

Xcode 3.2 is still available for download - in fact, 3.2.6 was released within the past week or two, so it's not exactly "old and busted." :-) Xcode 4's interface is very different, so given your tight schedule and your need to start from square one, you might be better off using 3.2 for now. That will certainly make it far easier to use the book you have.

Sherm Pendley
  • 13,556
  • 3
  • 45
  • 57