从它的超级视图中删除一个视图会导致内存错误 - 为什么?
问题描述:
Xcode是在我抛出一个错误:从它的超级视图中删除一个视图会导致内存错误 - 为什么?
malloc: * error for object 0x103f000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug
我找到了代码,直到一条线在那里我这样做:
- (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;
}
当我删除该errorful线,该错误消失。所以最后:我无法摆脱我的观点!
这是一个UIImageView,里面没有其他东西,只是显示图像。我做的是这样的:我创建一个UIView动画块,创建UIImageView,用self.myView = ...将它分配给retain属性,并且在动画完成后,我只想摆脱那个视图。所以我将它从超级视角中移除,然后将我的财产设置为零,从而让它消失 - 理论上是这样。
还有其他人遇到过这样的问题吗? iPhone SDK 3.0。
答
有在模拟器在SDK 3.0中的错误可能会导致这个错误:
iPhone development: pointer being freed was not allocated
它不会发生在模拟器中3.1+,或根据任何SDK版本的设备上。