开发者

object mysteriously getting deallocated

I'm having an issue with an object that gets deallocated somehow someway. I have used the various debugging techniques like enabling NSZombie etc to find the problematic object. It is a simple NSMutable Array object that I used to display my section header title in a grouped tableview. It is the object from which the title header is returned in the function:

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

where I return the value using objectAtIndex on the object mentioned above. I have ensured that it doesn't run out of bounds or anything. This grouped tableView appears on the left side of my开发者_运维百科 custom splitView controller. It all works fine in portrait mode where the left side comes in a popover. No issues. In landscape where it appears as a table I have this object deallocating itself mysteriously. The split view appears first no issues. Then I have a modal view coming on top of it. It is when I dismiss this modal view on top, the section header object deallocates mysteriously crashing the split view underneath the modal which tries to appear on the modal dismiss.

Any pointers or clues?

Thanks


Without code it will be really hard to find the problem.

Does the crash happen on a real device, the simulator or both? Are you retain/allocating and releasing the object manually or is it in a auto release pool?

Generally check your viewDidUnload, viewWillDisappear, didReceiveMemoryWarning methods and make sure everything you release is recreated in the appropriate methods. If you are using that array in multiple view controllers make sure to retain and release it in every view controller at the appropriate points.

One way to find out who is releasing the array would be:

Creating a subclass of NSMutableArray

@interface myNSMutableArray : NSMutableArray {}
@end

@implementation myNSMutableArray
-(oneway void)release {
    NSLog(@"Being released");
    NSLog(@"retainCount: %i", [self retainCount]);
    [super release];
}
@end

Change the type of your mystery array to myNSMutableArray, add a break point after the 2 NSLog lines and when the debugger arrives at the breakpoint ask GDB for a backtrace (bt command).


When you load (or reload) your array, did you retain it?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜