Reputation: 9545
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.
Upvotes: 0
Views: 596
Reputation: 104708
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.
Upvotes: 1
Reputation: 125037
-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.
Upvotes: 1