Hi, Sorry I haven't given full details. I just found where the exc_bad_access signal comes from. I have a controller object and a model object, both are created in the interface builder. So I suppose they are stored in the XIB document. That's why they are initialized automatically as you guys mentioned. My controller class has an IBOutlet variable which is an instance of that Model object. I did connect this IBOutlet to that Model object in the interface builder. So everything should be fine as expected. However, I declare a NSDictionary instance variable in my model object. This NSDictionary instance store some data I need. And I will create this NSDictionary instance by invoking: [NSDictionary dictionaryWithObjects:names forKeys:keys] Both names and keys are string NSArray. I will invoke this method inside my init method of my model object. So everything should be initialized when the Nib file is loaded(model object will be initialized and hence the NSDictionary will be initialized as well). Unfortunately, when I try to get value from that NSDictionary, I will get exc_bad_access signal, and I follow gdb, the NSDictionary instance seems to be corrupted. Every other instance else(all are primitive types) in that Model object are fine(contains correct value). So where does it go wrong? Hopefully I state things clearly this time. Thank you all.
On Mon, May 17, 2010 at 1:29 PM, Henry McGilton < appledevelo...@trilithon.com> wrote: > > On May 15, 2010, at 10:56 AM, Sai wrote: > > > Hi All, > > I am new to cocoa development. Suppose I have an iPhone application > follow > > the MVC design pattern. > > The Model is presented by an custom object. And I have declared an > instance > > of the Model Object as a IBOutlet > > in my Controller class. > > One assumes from your description here that there is a custom object in > your XIB document. > And, as you said, your Controller class has an IBOutlet declaration for the > Model. > > Is there an instance of your Controller class in the XIB document? > Did you connect that Controller's Model IBOutlet to the Model object itself > using Interface Builder? > > If it's not connected in the XIB document, you need to make the connection, > and then the alloc and init > you do as described below is no longer necessary. > > > > I found that every time I start my application, this > > instance of Model Object will be initialized. > > My first question is who called this init method, what for? > > The alloc and init are called when the NIB is loaded. > > > > > As I found that it will be initialized automatically, so I just send > message > > for that instance, and crashed at runtime > > with a exc_bad_access signal error. So I have to call alloc and init for > > that Model Object and assign the returned > > instance to the IBOutlet variable, then everything runs well. > > > My second question is if I have to allocate and initialized that Model > > Object for myself? Is it over-done for this > > initialization because it is called automatically before. > > Yes, but if you had made the connection from Controller to Model in the XIB > document, > you would not need to alloc and init a new instance. > > > My third question is where I should call the release method for this > > instance of Model Object? > > You release the Model object when you no longer need it. > > Best Wishes, > . . . . . . . . Henry > > _______________________________________________ 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