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?
 

HiRez

macrumors 603
Jan 6, 2004
6,265
2,630
Western US
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.
 

Sayer

macrumors 6502a
Jan 4, 2002
981
0
Austin, TX
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.
 

Darkroom

Guest
Dec 15, 2006
2,445
0
Montréal, Canada
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
 

crees!

macrumors 68020
Jun 14, 2003
2,018
245
MD/VA/DC
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?
 

Darkroom

Guest
Dec 15, 2006
2,445
0
Montréal, Canada
*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)
 

Cromulent

macrumors 604
Oct 2, 2006
6,812
1,100
The Land of Hope and Glory
*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.
 

Darkroom

Guest
Dec 15, 2006
2,445
0
Montréal, Canada
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.