문제

I am facing a bit strange problem with implementation of UIAccelerometer. I have a UITableViewController where I don't wanna use UIAccelerometer, but after pressing on of the rows I wanna activated one inside a UIViewController, everything is fine when I use simulator, but when I use device iPhone 3G to test it, I got EXC_BAD_ACCESS by pressing return button.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


     ShakeControl *percView = [[ShakeControl alloc] init];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:percView animated:YES];
     [percView release];


}

It works fine when I disable [percView release];, but it does not sounds like solution for. Any Idea would be appreciated.

Shake control implementation:

- (void)viewDidLoad {
    [super viewDidLoad];
    [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0 / kUpdateFrequency];
    [[UIAccelerometer sharedAccelerometer] setDelegate:self];

}

- (void)viewDidUnload {
    [super viewDidUnload];

    [[UIAccelerometer sharedAccelerometer] setDelegate:nil];
}

Thx

도움이 되었습니까?

해결책

The viewDidUnload method will get called only in specific case, such as memory warning. You have to remove the delegate in dealloc too.

다른 팁

Try releasing it after you dismiss it, I'm not sure if pushViewController retains.

You could setting the environment variables NSZombiesEnabled & NSAutoreleaseFreedObjectCheckEnabled with a value of 1. This will prevent objects from really being deallocated, then you should get console logs indicating where the over-release is coming from.

You could use Run With Performance Tools -> Allocations once you know which object is being over-released and see every location where a retain/release was called to spot the imbalance.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top