Dealloc 调用 UIView 子类
我找不到我拥有的对象被释放的原因。在什么情况下,当 uiview 对象的父视图尚未释放时,它会被释放?
背景: 对象 ObjectA 是 UIView 的子类,并在 UITableView 的子类 TableA 中的 tableHeaderView 中进行子查看。 TableC 是TableB 的子类,TableB 是TableA 的子类。
UITableView==> TableA(objectA 在这里为 tableHeaderView 实例化) ==>表B==> TableC
我目前在 TableC 中有 3 个部分,一切正常。如果我添加第四部分,则会在 ObjectA 上调用 dealloc。
I cannot find the reason why an object i have is being deallocated. In what circumstances would a uiview object be deallocated when its superview hasn't been?
Background:
The object, ObjectA, is a subclass of UIView and is subviewed in the tableHeaderView in a subclass of UITableView called TableA. TableC is a subclass of TableB, which is a subclass of TableA.
UITableView ==> TableA(objectA is instanced here for the tableHeaderView) ==> TableB ==> TableC
I currently have 3 sections in TableC and everything works fine. If I add a 4th section, then dealloc is called on ObjectA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果不是您释放视图,则通常会在超级视图卸载或交换内容视图时发生 - 也就是说,当您的子视图从视图图中删除时,您的子视图将被发送
release< /code> 消息(因为子视图由其父视图保留)。
在
-[MONSubview dealloc]
中设置断点并检查跟踪应该可以清楚地看出原因,尽管如果在自动释放池被销毁时您的视图正在被释放,那么它可能距离调用点很远,然后跟踪将没有用处。if it's not you that is releasing the view, it will typically occur when when the superview is unloading or swapping content views -- that is, when your subview is removed from the view graph, your subview will be sent a
release
message (because subviews are retained by their parent views).setting a breakpoint in
-[MONSubview dealloc]
and examining the trace should make the reason evident, although it could be miles from the callsite if your view is being dealloc'd when an autorelease pool is destroyed and then the trace will not be useful.-dealloc 在对象被释放、保留、分配或复制的次数相同的情况下被调用。就是这么简单。
如果您的视图被释放,即使它仍然是另一个视图的子视图,那么您就在某个地方过度释放了它。
-dealloc is called anytime an object is released as many times as it was retained, alloc'ed, or copied. It's that simple.
If your view is being deallocated even though it's still a subview of another view, you're over-releasing it somewhere.