1

I have a instance variable which is a NSMutableArray

@interface SummaryWindowController : NSWindowController {

    NSMutableArray *aBuffer;

The NSMutableArray is set using this method (called from the object that init'ed this object):

- (void)setGlobalStatusArray:(NSMutableArray *)myArray
{
    if (!aBuffer) {
        [myArray retain];
        NSLog(@"aBuffer not init , alloc init now");
        aBuffer = [[NSMutableArray alloc] initWithArray:myArray];
    }
    NSLog(@"--> Received buffer: %@",aBuffer);

}

The NSLog shows the contents of the array when that method runs:

2011-08-18 16:00:26.052 AppName[74751:1307] --> Recievied buffer: (
        {
        discription = DiskUsage;
        menu = "<NSMenuItem: 0x1005116e0 Hardware Status>";
        status = Warning;
    },

But in my method that uses this instance variable it no longer seems init'ed

- (IBAction)refreshButtonClicked:(id)sender
{
    NSLog(@"The user has clicked the update button");
    if (!aBuffer) {
        NSLog(@"refresh button not init");
    }
    NSLog(@"Buffer is currently:%@",aBuffer);
}

As when it gets to this point I see the following 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)

Which would indicate to me that aBuffer has been (auto?)released?

Any ideas why this would be doing this? I thought at first I had two distinct objects, one which I created by initing NSWindowController from the original controller:

   @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];

And one that was created when the nib load, identical but different objects however I now don't think thats the case as I don't see duplicate NSLogs any more, so I assume its just some basic memory issue with NSMutableArray(s)?

2 Answers 2

1

You are retaining myArray when you should be retaining aBuffer.

Sign up to request clarification or add additional context in comments.

2 Comments

I only was retaining myArray as it was a solution on another question, I tried adding both [aBuffer retain]; [myArray retain];
Also I don't think technically I should have to retain as I am using initWithArray.
0

Try using an

@property (nonatomic, retain) NSMutableArray *aBuffer

in your interface.

Next,

 @synthesize aBuffer

In your .m file. AFter that,

when you set your array, do it like this:

    self.aBuffer = [[NSMutableArray alloc] initWithArray:myArray];

Note the "self" so that you are specifying the property.

1 Comment

I have already tried making it a property, no go, did the above example just to make sure and it still is not an init. I am wondering if I need to move alloc/init it the init override method and use some other retained NSMUtableArray method to copy the array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.