UIAccelerometer EXC_BAD_ACCESS crash on device
-
28-09-2019 - |
문제
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.