Re: String Allocation inside drawRect:...
Re: String Allocation inside drawRect:...
- Subject: Re: String Allocation inside drawRect:...
- From: "I. Savant" <email@hidden>
- Date: Wed, 15 Apr 2009 10:11:23 -0400
On Wed, Apr 15, 2009 at 9:55 AM, Graham Cox <email@hidden> wrote:
> It's not illegal, though many will tell you it's not best practice
To elaborate: According to the documentation (and good sense),
-drawRect: should be as quick / lightweight as possible since it could
be called many times in rapid succession (especially when resizing and
animating).
If you have many strings to draw, you might try creating them all in
one go outside -drawRect: and storing them in a cache. Then -drawRect:
needs only to walk the cache and draw the strings. I also like to
cache string attributes (if they don't change / don't change
frequently), as they're a pretty complicated structure (a dictionary
containing attributes/values, and possibly an NSParagraphStyle which
is even more weight).
> Suggest you show the whole of drawRect:?
... as well as what you've found in the debugger (ie, the runtime
error and the line that's causing the problem).
--
I.S.
_______________________________________________
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