Removing a view from it's superview causes memory error - why?

Posted by mystify on Stack Overflow See other posts from Stack Overflow or by mystify
Published on 2010-03-11T12:06:58Z Indexed on 2010/03/19 3:31 UTC
Read the original article Hit count: 383

Xcode is throwing an error at me:

malloc: * error for object 0x103f000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

I tracked down the code until a line where I do this:

- (void)inputValueCommitted:(NSString *)animationID finished:(BOOL)finished context:(void *)context {
        // retainCount of myView is 2! (one for the retain-property, one for beeing a subview)
        [self.myView removeFromSuperview]; // ERROR-LINE !!
        self.myView = nil;
}

When I remove that errorful line, the error is gone. So in conclusion: I can't get rid of my view!

It's an UIImageView with nothing else inside, just showing an image. What I do is this: I create an UIView Animation Block, create that UIImageView, assign it to an retain-property with self.myView = ..., and after the animation is done, I just want to get rid of that view. So I remove it from it's superview and then set my property to nil, which lets it go away - in theory.

Did anyone else encounter such issues? iPhone SDK 3.0.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about memory-management