解除分配的实例 | “Malloc_history 无法检查进程 XYZ,因为该进程不存在。”

发布于 2024-10-14 20:08:30 字数 1520 浏览 4 评论 0原文

我有内存问题(是的;)我是 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; 0x17dfb0 。结果控制台返回:

malloc_history 无法检查进程 5838,因为该进程不存在

所以问题是:

  1. 有人能看到明显的保留, 这里发布有问题吗?
  2. 我怎样才能得到 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:

  1. Can someone see the obvious retain,
    release problem here?
  2. How can I get malloc_history <PID>
    <Address
    >
    working?

Thank you for your time, redirects and answers!

Christian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执笏见 2024-10-21 20:08:30

问题是您正在将一个自动释放的对象(您的[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 in self.pressureLabel = ....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文