Question

I have a simple application that counts down to midnight and then plays a beeping sound over and over again and blinks the label showing the time. So the label blinking uses an NSTimer, while the beeping goes on its own Thread, so that the pure C function (for the system sound id completion callback) can use [NSThread sleepForTimeInterval:...]; to wait a bit in between playing the alarm beep sound. So I get two error messages during execution saying theres no autorelease pool and it will just leak. Its because in the method that I call into a new thread, There's two @"Strings" that are used to create the System Sound ID (the file name and extension). Is there a way I can not use an autorelease pool since those are the only two things that ever try to use it. Thanks.

Or should I use two NSTimers instead of another thread..?

Ben Gottlieb's answer was right, however I decided to use another NSTimer instead because I forgot about how its not really synced to the time when you sleep the thread as the actual execution of the code before it takes a bit of time. And it makes things symmetrical ;).

Was it helpful?

Solution

Just create an autorelease pool in your thread method:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

...thread body...

[pool release];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top