Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 26, 2008, 10:50 PM   #1
zippyfly
macrumors regular
 
Join Date: Mar 2008
Does ObjC 2.0 mean no worrying about FREE and DEALLOC?

Does the garbage collection in 2.0 mean we no longer have to really worry about freeing memory to avoid leaks?

Can we just create objects and just move on with the code, without worrying to keep track and free them?

a.k.a. can we be lazy (read: efficiently focus on the program logic rather than housecleaning) and get away with it?

Thanks.

PS - sorry I meant "release" and "dealloc"
zippyfly is offline   0 Reply With Quote
Old Mar 27, 2008, 12:47 AM   #2
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Yes and no. You still need -finalize methods (the new equivalent of -dealloc) in cases where you have non-memory resources to free up (say, sockets), and you might need to be careful if you ever reference non-garbage-collected memory from garbage-collected memory (say, if you use a C library in your app). There are a few other caveats, but in general it's pretty simple.
Catfish_Man is offline   0 Reply With Quote
Old Mar 27, 2008, 01:00 AM   #3
aLoC
macrumors 6502a
 
Join Date: Nov 2006
Also the garbage collector only cleans up objects. If you just malloc a bunch of memory you'll have to clean it up yourself.
aLoC is offline   0 Reply With Quote
Old Mar 27, 2008, 01:11 AM   #4
ebel3003
macrumors 6502a
 
ebel3003's Avatar
 
Join Date: Jun 2007
Location: "The Google"
A few question: With Objective-C 2.0, calling [object release] doesn't matter anymore? Even if it doesn't, it would still be more efficient to clean up after yourself, right? Also, Objective-C 2.0 is included with Xcode 3.0, correct?
__________________
http://funnyvibe.net
MacBook Pro 15" (Late 2013 w/ 750M) | Samsung Galaxy S5 | Nexus 7 (2013)
ebel3003 is offline   0 Reply With Quote
Old Mar 27, 2008, 01:28 AM   #5
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
Quote:
Originally Posted by ebel3003 View Post
A few question: With Objective-C 2.0, calling [object release] doesn't matter anymore? Even if it doesn't, it would still be more efficient to clean up after yourself, right? Also, Objective-C 2.0 is included with Xcode 3.0, correct?
ObjC is part of the OS, not part of Xcode, but Xcode 3 does support compiling ObjC 2 programs. [object release] is just a "do nothing" with garbage collection turned on. If you want to give hints to the GC system you can use NSAutoreleasePool's -drain method, or the NSGarbageCollector class.
Catfish_Man is offline   0 Reply With Quote
Old Mar 27, 2008, 06:18 AM   #6
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by zippyfly View Post
Does the garbage collection in 2.0 mean we no longer have to really worry about freeing memory to avoid leaks?

Can we just create objects and just move on with the code, without worrying to keep track and free them?

a.k.a. can we be lazy (read: efficiently focus on the program logic rather than housecleaning) and get away with it?

Thanks.

PS - sorry I meant "release" and "dealloc"
You can be lazy. You still can't afford to be stupid. An object is not garbage as long as there is a usable pointer to it somewhere. So it would be a really, really stupid move to make a list of all objects that you don't care about, and put every object that you don't care about into that list...
gnasher729 is offline   0 Reply With Quote
Old Mar 27, 2008, 07:21 AM   #7
zippyfly
Thread Starter
macrumors regular
 
Join Date: Mar 2008
Hi - sorry I don't quite understand what you mean.

Say, I allocate a new object in my MAIN.

I then call some method inside that object, which creates its own objects, etc.

The next time I call the method, the instance creates OTHER new objects (e.g., to replace instance variable values) but I do not release the first objects (which are now obsolete, although I did not track them, nor did I issue a release command to the instance variables to free themselves before being assigned the newly created objects).

And I do this over and over and over.

Will the garbage collector release these objects for me?

(The instance variables no longer point to the underlying objects, evidently in this case)
zippyfly is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: Nervous about upgrading to Lion. Worried about Mail and iCal...is Lion for me? beyondthesmile Mac OS X 10.7 Lion 17 Aug 15, 2011 10:40 PM
NO iPAD 2 APPLE CASE.....NO WORRIES Blakjack iPad 41 Mar 17, 2011 05:00 AM
ARKHIPPO I iPhone 4 case - No worry about dropping sogod3 iPhone Accessories 4 Nov 19, 2010 06:22 PM
data only sim = no worries about ATT billing you for tethering JauCeKaden Jailbreaks and iOS Hacks 2 Jul 7, 2009 02:14 PM
How does new ObjC 2.0 properties accessors work? zippyfly Mac Programming 12 Jun 3, 2009 07:30 PM


All times are GMT -5. The time now is 11:50 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC