解除分配的实例 | “Malloc_history 无法检查进程 XYZ,因为该进程不存在。”
我有内存问题(是的;)我是 iOS 新手),在自定义 UIView 中使用以下方法:
头文件
....
@property (nonatomic, retain) NSString * pressureTextLabel;
....
实现绘制一个圆圈和一个带有与触摸相关的压力的标签。每个手指触摸都会创建此视图的一个对象:
- (void)drawRect:(CGRect)theRect{
CGRect rect = self.bounds;
CGRect ringRect = CGRectInset(rect, 100, 100);
// Outer ring.
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:ringRect];
ringRect = CGRectInset(rect, 60, 60);
[path appendPath:[UIBezierPath bezierPathWithOvalInRect:ringRect]];
path.usesEvenOddFillRule = YES;
[self.color set];
[path fill];
//text label
rect = CGRectMake(100, 20, 100, 100);
//This one seems to be the troublemaker
[pressureTextLabel drawInRect:rect withFont:[UIFont systemFontOfSize:14.0]];
}
只要控制器不调用以下方法来更新此特定触摸的感测压力,一切都会正常工作。
-(void) setTouchPressureTo: (float) pressure{
pressureTextLabel = [NSString stringWithFormat:@"%f", pressure];
[self setNeedsDisplay];
}
我收到以下错误:
*** -[CFString drawInRect:withFont:]: message sent to deallocated instance 0x16e8c0
一旦应用程序崩溃,这使我调查调试控制台中的内存跟踪:shell malloc_history
malloc_history 无法检查进程 5838,因为该进程不存在
。
所以问题是:
- 有人能看到明显的保留, 这里发布有问题吗?
- 我怎样才能得到
malloc_history
> 在职的?<地址
感谢您的时间、重定向和回答!
基督教
I have memory problem (yes ;) I am new to iOS) with the following method in a custom UIView:
Header file
....
@property (nonatomic, retain) NSString * pressureTextLabel;
....
Implementation draws a circle and a label with the pressure associated to the touch. Every finger touch creates a object of this view:
- (void)drawRect:(CGRect)theRect{
CGRect rect = self.bounds;
CGRect ringRect = CGRectInset(rect, 100, 100);
// Outer ring.
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:ringRect];
ringRect = CGRectInset(rect, 60, 60);
[path appendPath:[UIBezierPath bezierPathWithOvalInRect:ringRect]];
path.usesEvenOddFillRule = YES;
[self.color set];
[path fill];
//text label
rect = CGRectMake(100, 20, 100, 100);
//This one seems to be the troublemaker
[pressureTextLabel drawInRect:rect withFont:[UIFont systemFontOfSize:14.0]];
}
all works fine as long as this following method is not called by the controller to update the sensed pressure for this particular touch.
-(void) setTouchPressureTo: (float) pressure{
pressureTextLabel = [NSString stringWithFormat:@"%f", pressure];
[self setNeedsDisplay];
}
I get the following error:
*** -[CFString drawInRect:withFont:]: message sent to deallocated instance 0x16e8c0
which made me investigate the memory trace in the debug console once the application crashed: shell malloc_history <PID> 0x17dfb0
. As result the console returns:
malloc_history cannot examine process 5838 because the process does not
exist.
So here the question:
- Can someone see the obvious retain,
release problem here? - How can I get
malloc_history <PID>
>
<Address
working?
Thank you for your time, redirects and answers!
Christian
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您正在将一个自动释放的对象(您的
[NSString stringWithFormat...]
)分配给ivar(PressureTextLabel
)。您应该改用属性访问,如self.PressureLabel = ...
中所示。The problem is you're assigning an autoreleased object (your
[NSString stringWithFormat...]
) to an ivar (pressureTextLabel
). You should be using property access instead, as inself.pressureLabel = ...
.