-(BOOL)createTimer
{
stRs232Timer* pEvent = malloc(sizeof(stRs232Timer));
pEvent->bPersistent = YES; // setup timer structure
pEvent->wAppTimerId = 95;
pEvent->uPeriod = 50;
pEvent->bStopped = NO;
pEvent->uExpirationTime = 10;
NSLog(@"bPersistent:%d",pEvent->bPersistent);
NSLog(@"wAppTimerId:%d",pEvent->wAppTimerId);
NSLog(@"uPeriod:%d",pEvent->uPeriod);
NSLog(@"bStopped:%d",pEvent->bStopped);
NSData* myData = [NSData dataWithBytes:(stRs232Timer*)pEvent length:sizeof(stRs232Timer*)];
wTimerId = 99;
pEvent->uPeriod = 51;
myData = [NSData dataWithBytes:(stRs232Timer*)pEvent length:sizeof(stRs232Timer*)];
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
wTimerId = 96;
pEvent->uPeriod = 52;
myData = [NSData dataWithBytes:(stRs232Timer*)pEvent length:sizeof(stRs232Timer*)];
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
wTimerId = 97;
pEvent->uPeriod = 53;
myData = [NSData dataWithBytes:(stRs232Timer*)pEvent length:sizeof(stRs232Timer*)];
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
wTimerId = 98;
pEvent->uPeriod = 54;
myData = [NSData dataWithBytes:(stRs232Timer*)pEvent length:sizeof(stRs232Timer*)];
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
wTimerId = 95;
pEvent->uPeriod = 55;
myData = [NSData dataWithBytes:(stRs232Timer*)pEvent length:sizeof(stRs232Timer*)];
[m_cAppIdMap setObject:myData forKey:[NSNumber numberWithUnsignedShort:wTimerId]];
NSLog(@"The dictionary count now is:%d",[m_cAppIdMap count]);
NSLog(@"The dictionary values now is:");
NSLog(@"%@",m_cAppIdMap);
[m_cPendingEventList addObject:myData];
NSLog(@"EventList:%@",m_cPendingEventList);
[self ChangeTimer:95 withPeriod:10];
free(pEvent);
return YES;
}
-(BOOL)ChangeTimer:(unsigned short)wTimerIds withPeriod:(uint8_t)uPeriod
{
stRs232Timer* pEvent;
NSLog(@"Into the changeTimer");
pEvent = (stRs232Timer*)[m_cAppIdMap objectForKey:[NSNumber numberWithUnsignedShort:wTimerIds]];
NSLog(@"The val is:%@",pEvent);
if(pEvent!=nil){
pEvent->bStopped = NO;
pEvent->uPeriod = uPeriod;
NSLog(@"completed");
}
return YES;
}
main.m
----------
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSArray1* arr = [[NSArray1 alloc]init];
[arr createTimer];
[pool drain];
return 0;
}
Я получаю исключение времени выполнения EXC_BAD_ACCES. Почему это так. Я не обращаюсь ни к какой освобожденной памяти.
РЕДАКТИРОВАНИЕ:
2011-05-30 11:21:45.191 NSArray[1091:a0f] bPersistent:1
2011-05-30 11:21:45.194 NSArray[1091:a0f] wAppTimerId:95
2011-05-30 11:21:45.195 NSArray[1091:a0f] uPeriod:50
2011-05-30 11:21:45.195 NSArray[1091:a0f] bStopped:0
2011-05-30 11:21:45.196 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110180 of class NSConcreteData autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.196 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x1001102f0 of class NSConcreteData autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.197 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110410 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.197 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110a70 of class NSConcreteData autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.198 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110ab0 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.198 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110ad0 of class NSConcreteData autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.199 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110b10 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.199 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110b30 of class NSConcreteData autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.200 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100110b70 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.201 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x1001109e0 of class NSConcreteData autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.201 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x1001105d0 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.202 NSArray[1091:a0f] The dictionary count now is:5
2011-05-30 11:21:45.202 NSArray[1091:a0f] The dictionary values now is:
2011-05-30 11:21:45.203 NSArray[1091:a0f] {
98 = <5f000136 000a0000>;
97 = <5f000135 000a0000>;
96 = <5f000134 000a0000>;
99 = <5f000133 000a0000>;
95 = <5f000137 000a0000>;
}
2011-05-30 11:21:45.203 NSArray[1091:a0f] EventList:(
<5f000137 000a0000>
)
2011-05-30 11:21:45.204 NSArray[1091:a0f] Into the changeTimer
2011-05-30 11:21:45.204 NSArray[1091:a0f] *** __NSAutoreleaseNoPool(): Object 0x100111130 of class NSCFNumber autoreleased with no pool in place - just leaking
2011-05-30 11:21:45.205 NSArray[1091:a0f] The val is:<5f000137 000a0000>
2011-05-30 11:21:45.205 NSArray[1091:a0f] completed
Это вывод, который я получаю, когда удаляю NSAutoreleasePool и [сток стока].
Если я не удаляю оба этих параметра, я получаю EXC_BAD_ACCESS как исключение времени выполнения. Когда я отлаживаюсь, я получаю исключение (EXC_BAD_ACCESS), когда дело доходит до [утечки пула]; заявление.
Я не мог выяснить, почему это происходит.