CGPath占用内存较多
这是我曾经面临过的一个非常艰巨的挑战。当手指移动时我会画线。创建这些线条是为了绕过我的绘图视图中存在的图像视图。我正在使用下面的代码。
代码:-
-(void) paintLinesinContext:(CGContextRef)context{
for (Line *line in lines) {
NSMutableArray *arrayOfPoints=[line getPointsArray];
CGContextBeginPath(context);
int numberofPoints=[arrayOfPoints count] ;
CGPoint points[numberofPoints];
int index=0;
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
if (line==tmpline) {
float dashPhase=10;
float dashPattern[3]={5,5};
CGContextSetLineDash(context, dashPhase, dashPattern, 2);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
}
for (NSValue *pointObject in arrayOfPoints) {
points[index]= [pointObject CGPointValue];
if (index==0) {
CGContextMoveToPoint(context, points[index].x,points[index].y);
}
else {
CGContextAddLineToPoint(context, points[index].x, points[index].y);
}
index++;
}
CGContextStrokePath(context);
float dashPhase=10;
float dashPattern[3]={1,0};
CGContextSetLineDash(context, dashPhase, dashPattern, 2);
}
}
我的问题是,我的应用程序由于内存不足而崩溃。当我使用仪器中的分配来查看它时,我注意到 CGPath 占用了更多内存。不管你信不信。我的应用程序以 48MB 运行,然后跳转到 96MB,其中 90MB 是 CGPath。我不知道是什么原因,谁能帮帮我。
This is a very much daunting challenge I have ever faced. Im drawing lines when the finger is moved. The lines are created such that they bypass the imageviews presnt in my drawingview. I`m using below code.
Code:-
-(void) paintLinesinContext:(CGContextRef)context{
for (Line *line in lines) {
NSMutableArray *arrayOfPoints=[line getPointsArray];
CGContextBeginPath(context);
int numberofPoints=[arrayOfPoints count] ;
CGPoint points[numberofPoints];
int index=0;
CGContextSetStrokeColorWithColor(context, [[UIColor blackColor] CGColor]);
if (line==tmpline) {
float dashPhase=10;
float dashPattern[3]={5,5};
CGContextSetLineDash(context, dashPhase, dashPattern, 2);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
}
for (NSValue *pointObject in arrayOfPoints) {
points[index]= [pointObject CGPointValue];
if (index==0) {
CGContextMoveToPoint(context, points[index].x,points[index].y);
}
else {
CGContextAddLineToPoint(context, points[index].x, points[index].y);
}
index++;
}
CGContextStrokePath(context);
float dashPhase=10;
float dashPattern[3]={1,0};
CGContextSetLineDash(context, dashPhase, dashPattern, 2);
}
}
My problem is, my app is getting crashed because of low memory. When I looked into it using allocations in instruments, I noticed that CGPath is occupying more memory. Believe it or not. My app is running at 48MB and jumps to 96 MB out of which 90MB is CGPath. I don know what is the reason Can anyone help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论