Hi Jack, Thank you for your quick response. Your answer is very useful. Since I have pasted some of my codes in the previous mail. I just wonder if you have any comments on my codes, anything I can improve for this little app? Any advice will be very appreciated.
On Wed, May 19, 2010 at 5:07 PM, Jack Nutting <jnutt...@gmail.com> wrote: > On Wed, May 19, 2010 at 10:48 AM, Sai <jche...@gmail.com> wrote: > > 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? > > When you've just loaded a nib file, there can be all sorts of > auxiliary stuff going on that you're not aware of (and can't really be > aware of). To give an example off the top of my head, the nib-loading > mechanism probably has a list of objects that it's going to send > "awakeFromNib" to, which are held temporarily in an NSArray (which > retains its contents). > > For this reason and many others, you should *never* rely on the > retainCount to give you any useful information. Seriously, just don't > even call that method, ever. All you need to do is make sure your > alloc/copy/retain calls are each matched by a corresponding > release/autorelease somewhere, which it looks like they are in your > code (using properties helps a lot). > > > 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. > > This is normal behavior for both Cocoa apps on Mac OS X, and iPhone > apps. Rather than manually freeing a lot of memory, byte by byte > (which will all be freed in one fell swoop when the process exits > anyway), an app that is quitting just quits, which is a lot faster. > If there's something in particular you need to do when the app quits > (saving some data or something) you should implement one of the > UIApplicationDelegate methods that tells you when the application is > about to terminate. > > -- > // jack > // http://nuthole.com > // http://learncocoa.org > _______________________________________________ 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