我有一个5选项卡栏控制器iPad应用程序。 其中一个选项卡(EKG)导致内存问题。我已经运行了仪器,所有我可以看到的是,malloc
分配不断增加,大约12分钟后,我的所有View Controller首先获得didReceiveMemoryWarning
级别1,然后是级别2,然后是SigAbort 0 termination
。在iPad上导致内存问题的drawRect
应用程序设计工作的方式是当EKG选项卡处于活动状态时,每200毫秒触发一个setNeedsDisplay
,以便在整个屏幕上绘制(绘制)EKG样本。当我让应用程序正常运行时,它会在约12分钟后终止。
但是,如果我保留setNeedsDisplay
并注释掉drawRect
中的代码,它将永远运行 。我不是我“的drawRect”知道任何内存分配,但有人做这些mallocs
下面是我的drawRect
代码:
- (void) drawRect : (CGRect) rect
{
int i, ii, x = 0, xx, y;
fEcgDraw = YES;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth (context, 1);
HH = 376;
if (fEcgErase == YES)
{
CGContextSetStrokeColorWithColor (context,
[UIColor blackColor].CGColor);
/*==============================================================================*/
/* Erase the last screen. */
/*==============================================================================*/
for (i = 0; i < 120; i++)
{
CGContextMoveToPoint (context,
ECGX[x],
(HH - ECGS[x]));
CGContextAddLineToPoint (context, ECGX[(x + 1)],
(HH - ECGS[((x + 1) % 119)]));
x++;
} // end - for (i = 0; i < 120; i++)
CGContextStrokePath (context);
fEcgErase = NO;
} // end - if (fEcgErase == YES)
else if (fECGLOOP)
{
xx = 1;
x = 0;
y = YY;
ii = 0;
for (i =
{
// if (xx == 1)
{
/*==============================================================================*/
/* First erase the prior ECG A/D plot value. */
/*==============================================================================*/
CGContextSetStrokeColorWithColor (context,
[UIColor blackColor].CGColor);
CGContextMoveToPoint (context,
ECGX[x],
(HH - ECGS[x]));
CGContextAddLineToPoint (context,
ECGX[(x + 1)],
(HH - ECGS[((x + 1))]));
CGContextStrokePath (context);
/*==============================================================================*/
/* Now plot the next ECG A/D plot value. */
/*==============================================================================*/
CGContextSetStrokeColorWithColor (context,
[UIColor whiteColor].CGColor);
CGContextMoveToPoint (context,
ECGX[x],
(HH - ECGY[y]));
CGContextAddLineToPoint (context,
ECGX[(x + 1)],
(HH - ECGY[((y + 1) % 119)]));
CGContextStrokePath (context);
ECGS[x] = ECGY[y];
x++;
y = ((y + 1) % 119);
} // end - if (xx == 1)
} // end - for (i = 0; i < 120; i++)
y = ((y + count1) % 119);
YY = y;
count1 = 0;
} // end - if (fEcgErase == YES)
fEcgDraw = NO;
} // end - 'drawRect'
/*===============================END OF FUNCTION================================*/
我已经尝试注释掉“的drawRect”,并在“setNeedsDisplay”离开,这使问题消失。我不理解你对iver&gvars的评论,特别是gvars,因为根据定义,他们只有一个实例。至于ivars,我不明白怎么可能有多个,因为没有类实例可以分配更多的ivars。 –