Search code examples
objective-ciosmemory-managementdeallocmalloc-history

Deallocated instance | "Malloc_history cannot examine process XYZ because the process does not exist."


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


Solution

  • 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 = ....