I have define a NSMutableArray in .h file
NSMutableArray *arrayBatLevel;
init it in .m file
- (void)viewDidLoad {
[super viewDidLoad];
[self DataTimer];
}
-(void)DataTimer
{
[recordDataTimer invalidate];
recordDataTimer = [NSTimer scheduledTimerWithTimeInterval:[timeInterval.text floatValue]
target:self
selector:@selector(recordData)
userInfo:nil
repeats:YES];
}
-(void)recordData
{
if ([aSwitch isOn] == YES) {
if (arrayBatLevel == nil) {
arrayBatLevel = [[NSMutableArray alloc] init];
NSLog(@"alloc arrayBatLevel");
}
[arrayBatLevel addObject:batLevel.text];
}
}
and release in dealloc
- (void)dealloc {
[arrayBatLevel release];
[super dealloc];
}
but, it seems it’s not releasing all the objects inside the NSMutableArray.
When I exit this app and run it gain, these objects still in NSMutableArray, why?
Your problem is not with the array, it’s with the objects inside the array. You don’t indicate where “batLevel” came from. I’m guessing that “batLevel” is retained somewhere else, and with it “batLevel.text”.