我有一个实例变量,它是 NSMutableArray
@interface SummaryWindowController : NSWindowController {
NSMutableArray *aBuffer;
NSMutableArray 使用此方法设置(从初始化此对象的对象调用):
- (void)setGlobalStatusArray:(NSMutableArray *)myArray
{
if (!aBuffer) {
[myArray retain];
NSLog(@"aBuffer not init , alloc init now");
aBuffer = [[NSMutableArray alloc] initWithArray:myArray];
}
NSLog(@"--> Received buffer: %@",aBuffer);
}
NSLog 在该方法运行时显示数组的内容:
2011-08-18 16:00:26.052 AppName[74751:1307] --> Recievied buffer: (
{
discription = DiskUsage;
menu = "<NSMenuItem: 0x1005116e0 Hardware Status>";
status = Warning;
},
但是在我使用这个实例变量的方法中,它似乎不再被初始化
- (IBAction)refreshButtonClicked:(id)sender
{
NSLog(@"The user has clicked the update button");
if (!aBuffer) {
NSLog(@"refresh button not init");
}
NSLog(@"Buffer is currently:%@",aBuffer);
}
当它到达这一点时,我看到以下 NSLog:
2011-08-18 16:04:25.301 AppName[74829:1307] The user has clicked the update button
2011-08-18 16:04:25.303 AppName[74829:1307] refresh button not init
2011-08-18 16:04:25.304 AppName[74829:1307] Buffer is currently:(null)
哪个会向我表明 aBuffer 已(自动?)释放?
任何想法为什么会这样做?起初我以为我有两个不同的对象,一个是通过从原始控制器初始化 NSWindowController 创建的:
@interface AppName_AppDelegate : NSObject
NSMutableArray *globalStatusArray;
@implementation AppName_AppDelegate
if ( summaryWindow ) {
[summaryWindow release];
} // end if
summaryWindow = [[SummaryWindowController alloc] initWithWindowNibName:@"SummaryWindow" owner:globalStatusController];
[summaryWindow showWindow:self];
[summaryWindow setGlobalStatusArray:globalStatusArray];
还有一个是在 nib 加载时创建的,相同但不同的对象,但是我现在不认为是这种情况,因为我不再看到重复的 NSLog,所以我认为它只是 NSMutableArray(s) 的一些基本内存问题?