简体   繁体   English

从其超级视图中删除视图会导致内存错误-为什么?

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

Xcode is throwing an error at me: Xcode向我抛出错误:

malloc: * error for object 0x103f000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug malloc: *对象0x103f000错误:未分配要释放的指针*在malloc_error_break中设置一个断点进行调试

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. 这是一个UIImageView,里面没有其他内容,仅显示图像。 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. 我要做的是:创建一个UIView动画块,创建该UIImageView,使用self.myView = ...将其分配给保留属性,动画完成后,我只想摆脱该视图。 So I remove it from it's superview and then set my property to nil, which lets it go away - in theory. 所以我从它的超级视图中删除了它,然后将我的属性设置为nil,这使它消失了-从理论上讲。

Did anyone else encounter such issues? 还有其他人遇到过此类问题吗? iPhone SDK 3.0. iPhone SDK 3.0。

There a bug in Simulator in SDK 3.0 that can cause that error: SDK 3.0中的模拟器中存在一个错误,可能导致该错误:

iPhone development: pointer being freed was not allocated iPhone开发:指针未释放

It doesn't occur in Simulator in 3.1+, or on the device under any SDK version. 它不会在3.1+的Simulator中或任何SDK版本的设备上发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM