开发者

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

开发者 https://www.devze.com 2022-12-23 02:02 出处:网络
Xcode is throwing an error at me: malloc: * error for object 0x103f000: pointer being freed was not allocated

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 conclusio开发者_C百科n: 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.


There a bug in Simulator in SDK 3.0 that can cause that error:

iPhone development: pointer being freed was not allocated

It doesn't occur in Simulator in 3.1+, or on the device under any SDK version.

0

精彩评论

暂无评论...
验证码 换一张
取 消