Hi all,

I have gone through the Memory Management Programming Guide document last
night, and modify my codes a little bit.
Even the program runs well without crashing, but I still have some questions
remained. I will attach some of my codes as
follow:

1. I have both Controller Object and MyModel Object defined in my interface
builder. I also make a connection between them.
- some codes of Controller interface file:
@interface Controller : NSObject {
    IBOutlet UIButton *beginButton;
    IBOutlet UIButton *endButton;
    IBOutlet UILabel *nameLabel;
    IBOutlet UILabel *numberLabel;
    MyModel *myModel;
}

@property (nonatomic, retain) IBOutlet MyModel *myModel;

/* some methods defined here as well */
@end

- some codes of Controller implementation file:
#import "Controller.h"

@implementation Controller

@synthesize myModel;

- (void) awakeFromNib {
    /*initialize some UI here */

    NSLog(@"myModel retain count: %d", [myModel retainCount]);
    NSLog(@"controller retain count: %d", [self retainCount]);
}

/* some IBAction method defined here */

- (void) dealloc {
    NSLog(@"Controller dealloc method invoked!");   // dealloc checkpoint 1
    [myModel release];
    myModel = nil;
    [super dealloc];
}


2. I have implemented the Model object as follow:
- some codes of MyModel interface file:
@interface MyModel : NSObject {
    int number;
    NSDictionary * modelNames;
}

@property int number;

- (id) initWithNumber:(int)numValue;
- (void) initModelNames;

/* some other methods defined here */
@end

- some codes of MyModel implementation file:
@implementation MyModel

@synthesize number;

- (id) init {
    return [self initWithNumber:5];
}

- (id) initWithNumber(int)numValue {
    if (self = [super init]) {
        self.number = numValue;
        [self initModelNames];
    }
    return [self autorelease];
}

- (void) initModelNames {
    /* setup two NSArray: strNames, strKeys */
    modelNames = [[NSDictionary dictionaryWithObjects:strNames
forKeys:strKeys] retain];
}

- (void) dealloc {
    [modelNames release];
    modelNames = nil;
    [super dealloc];
    NSLog(@"MyModel dealloc method invoked!"); //dealloc checkpoint 2
}

I have two questions:
1. Look at the awakeFromNib method of Controller, my output of the retain
count to the console are
myModel retain count: 5
controller retain count: 17
both number are very surprised me, why is that? I suppose they should be 2
or 1?
Can anyone explain please?

2. No matter wether I quit the program from my iPhone simulator or I quit
the simulaor, none of the
dealloc method is invoked because there is no any NSLog output from the
deallocmethod to the console.
Why? I know this probably can be solved if I have the retain count as I
expected.

best regards
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to