Re: Cocoa view gets sluggish over time
Re: Cocoa view gets sluggish over time
- Subject: Re: Cocoa view gets sluggish over time
- From: Artemiy Pavlov <email@hidden>
- Date: Mon, 20 Dec 2010 21:27:08 +0200
Thank you very much for these tips, Andy! They are really helpful. I
have only started to learn Cocoa three weeks ago and answers on this
list really gave me a good kick.
All the best,
Artemiy.
You seem to have solved your main problem, so I'll just comment on a
couple of other things.
(1) You are over-releasing PatternStepLabelString.
stringWithFormat: returns an object you do not own, which means you
are not responsible for releasing it. In fact, you must not release
it, because releasing an object too many times will cause your
program to crash.
Note that it is correct to release PatternStepLabel, because alloc
returns an object that you do own. You must release it (either
right away or later via autorelease), or it will be a memory leak.
See <http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html
>, in particular "Memory Management Rules".
(2) Unless you need PatternStepLabelString for something else, you
can eliminate it altogether by using setIntValue: instead of
setStringValue: as follows.
[PatternStepLabel setIntValue:i];
(3) The convention in Cocoa is to begin variables with lowercase
letters, like this:
NSTextField *patternStepLabel;
NSString *patternStepLabelString;
If you work with other Cocoa developers, or even if you paste code
into emails like this one, you can make the code easier for others
to read by sticking to convention.
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden