Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MDMstudios

macrumors member
Original poster
Mar 18, 2008
36
0
Hello everyone, I have a question for yall.
Say I have a some of IBOutlets like this.

Code:
IBOutlet NSTextField text1;
IBOutlet NSTextField text2;
IBOutlet NSTextField text3;

Should put these items in the dealloc method? Or since I am not allocating them should I just leave them?
 
Hello everyone, I have a question for yall.
Say I have a some of IBOutlets like this.

Code:
IBOutlet NSTextField text1;
IBOutlet NSTextField text2;
IBOutlet NSTextField text3;

Should put these items in the dealloc method? Or since I am not allocating them should I just leave them?
Right, don't release anything you don't retain. In the case of nib objects, the runtime allocates them for the nib, so it will take care of disposing of them too.
 
Also be aware that method names with init* will need to be explicitly released (dealloc) when you are done with them.

Example:

Code:
movie = [[QTMovie alloc] initWithFile:movieFileToPlayPath error:nil]; // these are NOT placed into the autorelease pool
	
movie = [QTMovie movieWithFile:movieFileToPlayPath error:nil]; // these are placed into the autorelease pool

The first line needs to be released with additional code you write, the second line will be released automatically.

This can be a source of apparently random crashes later on as an object you expected to be there had been automatically freed by the framework.
 
ohh, i just read about this in my dev book.

new, alloc, init, or copy should be released, as they retain themselves when created, but everything else concerning memory management is taken care of automatically in the autorelease pool...

at least i think that's what i read - but it was a touch confusing, so maybe i'm either only half right or totally wrong. :p
 
Also be aware that method names with init* will need to be explicitly released (dealloc) when you are done with them.

Example:

Code:
movie = [[QTMovie alloc] initWithFile:movieFileToPlayPath error:nil]; // these are NOT placed into the autorelease pool
	
movie = [QTMovie movieWithFile:movieFileToPlayPath error:nil]; // these are placed into the autorelease pool

The first line needs to be released with additional code you write, the second line will be released automatically.

This can be a source of apparently random crashes later on as an object you expected to be there had been automatically freed by the framework.

Does this change when using garbage collection?
 
*i think* retain and release statements are not needed if garbage collection is turned on... but if garbage collection is turned on, the app's deployment target will be SDK 10.5 in which case i'm pretty sure you will not be able to make a universal binary app (so it'll be only compatible with Mac OS 10.5, and will not work with Mac OS 10.4 or earlier)
 
*i think* retain and release statements are not needed if garbage collection is turned on... but if garbage collection is turned on, the app's deployment target will be SDK 10.5 in which case i'm pretty sure you will not be able to make a universal binary app (so it'll be only compatible with Mac OS 10.5, and will not work with Mac OS 10.4 or earlier)

Universal binaries have nothing to do with the OS version. A universal binary is one which has two executables, one compiled for Intel machines, the other for PPC machines. Universal binaries are available on both Mac OS X Tiger and Leopard. Targetting 10.5 still enables you to build universal binaries.
 
Universal binaries have nothing to do with the OS version. A universal binary is one which has two executables, one compiled for Intel machines, the other for PPC machines. Universal binaries are available on both Mac OS X Tiger and Leopard. Targetting 10.5 still enables you to build universal binaries.

woops! hah... you're absolutely right... what i meant to say then is that garbage collection will only work for apps designed for 10.5... the end :D
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.