Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Mar 26, 2008, 11: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, 01: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, 02: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, 02: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, 02: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, 07: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, 08: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

Similar Threads
thread Thread Starter Forum Replies Last Post
Facebook contacts access on iPhone 5 worrying stylinexpat iPhone and iPod touch Apps 14 Feb 26, 2014 09:50 AM
Resolved: Quick question about C++ and ObjC Luigi3 iPhone/iPad Programming 2 Nov 12, 2012 10:50 AM
Please help! Worrying problem in Garageband Lamius Digital Audio 0 Nov 2, 2012 09:35 AM
why is my dealloc not called? Tex-Twil iPhone/iPad Programming 2 Jul 19, 2012 03:35 PM

Forum Jump

All times are GMT -5. The time now is 03:26 PM.

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

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