2

I have a UIView on which I draw a UIBezierPath by finger. When I rezoom the view (say after a path is drawn) a redraw function is triggered, which rescales the BezierPath:

- (void)redrawPathsWithScale:(float)scale
{
    [_path applyTransform:CGAffineTransformMakeScale(scale, scale)];
    [self setNeedsDisplay];
}

setNeedsDisplay causes drawRect to get called. Now every time I zoom in to a absolute scale somewhere near x6 I immediately get a memory warning, and the App crashes.

My drawRect method looks like this:

- (void)drawRect:(CGRect)rect
{   
    [_path strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];
}

The Curious thing is: Not implementing drawRect at all removes the memory warning. Implementing an empty drawRect still causes a crash!

Hasib Samad
  • 1,081
  • 1
  • 20
  • 39
  • have you tried to trace the allocations in instruments to see what exactly is responsible for the memory growth? – Tobi Oct 23 '12 at 10:34
  • Well. There is actually no memory growth. This is a very strange issue. Allocations (living bytes) stay constantly at about 8MB until the app crashes. See my other question relating this issue: http://stackoverflow.com/questions/13028427/ipad-low-memory-warning-although-no-other-apps-are-running-and-my-app-allocate – Hasib Samad Oct 23 '12 at 10:41
  • I am working on a similar thing and I found that the frequency that you call draw rect can trigger a memory warning and crash. For instance if I call drawRect every 0.25seconds my app crashes but if I call it every 0.5second it is fine. Odd behaviour to say the least. Are you using a timer to redraw at all? – damien murphy. Nov 02 '12 at 18:09

1 Answers1

1

Does adding [super drawRect:rect]; make any difference?

The Apple Documentation for drawRect states:

If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation.

If you're subclassing UIView, you should be fine but it might be worth checking this just in case.

Zack Brown
  • 5,990
  • 2
  • 41
  • 54
  • Im subclassing UIView directly. Still, I tried to call the super method at the beginning of drawRect. Nothing changed. – Hasib Samad Oct 23 '12 at 10:24
  • This fixed it for me. I was subclassing UIControl without a super drawRect. Thanks! – Jon Dec 07 '12 at 13:32