Here is the thing: I have a view, which contains complicated content that need be redraw after related data updated. I use multiple views to implement this, more likely that one large view contains several subviews, and every subview may also have several subviews. All these views override their own drawRect: method.
The question is that the complicated view takes large memory usage, and I want to know why drawRect: cause a large memory usage, so I can optimizing my view.
Is there anyone give me a hand? Thanks.
EDIT: I just noticed you didn’t actually say whether you’re talking about iOS or Mac OS X. I assumed iOS; if it’s OS X you’re on your own 😛 For future reference, it’s good practice to tag your question with the OS or framework you’re developing for.
Basically, drawRect is the most memory-heavy way of dealing with views. iOS can’t optimise the subview system like it normally does because it doesn’t know what you’re doing, so there’s multiple levels of frame buffers that need to be redrawn before the frame reaches the screen. Consider whether entire views need to be redrawn, and seriously consider using the subview layout system (needsLayout: and friends) or Core Animation to do what you need.
If you seriously need drawRect:, don’t give your view any subviews. Subviews do not play nice with drawRect. Either do all your drawing in the view you need, or use the layout subsystem or CA.
Finally, last year’s WWDC sessions are good help here. Session 131 “Performance Optimisation on iOS” and session 104 “Designing apps with scroll views” both talk about UIView performance. Here’s the link to the sessions if you’ve lost it: WWDC session videos