FROM : Jens Alfke
DATE : Fri May 02 20:03:22 2008
On 2 May '08, at 9:32 AM, Western Botanicals wrote:
> The reason I put the AutoReleasePools in there is because I am
> getting these errors in the output. So if you can help me find what
> is wrong that would be great. Every time I create a Date or Timer
> object, I get one or both of these:
You're probably running this as a GUI-less tool process, i.e. directly
calling your code from main(). If you do this, you need to create a
top-level autorelease pool before calling into your code. In general,
main() looks like:
int main( int argc, const char **argv ) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
int result = 0;
// your program code goes here
[pool drain];
return result;
}
In a GUI application (or even a runloop-based tool) you don't have to
worry about this, because NSRunLoop makes sure to create an
autorelease pool whenever it calls into application code.
Speaking of runloops, your test code needs to idle the runloop in
between its tests, to give the timer a chance to expire entries. You
currently have some (commented-out) usleep calls, but those won't
work, because the runloop is on your thread and has to be explicitly
given time to run. You can replace those with
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate
dateWithTimeIntervalSinceNow: 0.25];
—Jens
DATE : Fri May 02 20:03:22 2008
On 2 May '08, at 9:32 AM, Western Botanicals wrote:
> The reason I put the AutoReleasePools in there is because I am
> getting these errors in the output. So if you can help me find what
> is wrong that would be great. Every time I create a Date or Timer
> object, I get one or both of these:
You're probably running this as a GUI-less tool process, i.e. directly
calling your code from main(). If you do this, you need to create a
top-level autorelease pool before calling into your code. In general,
main() looks like:
int main( int argc, const char **argv ) {
NSAutoreleasePool *pool = [NSAutoreleasePool new];
int result = 0;
// your program code goes here
[pool drain];
return result;
}
In a GUI application (or even a runloop-based tool) you don't have to
worry about this, because NSRunLoop makes sure to create an
autorelease pool whenever it calls into application code.
Speaking of runloops, your test code needs to idle the runloop in
between its tests, to give the timer a chance to expire entries. You
currently have some (commented-out) usleep calls, but those won't
work, because the runloop is on your thread and has to be explicitly
given time to run. You can replace those with
[[NSRunLoop currentRunLoop] runUntilDate: [NSDate
dateWithTimeIntervalSinceNow: 0.25];
—Jens
| Related mails | Author | Date |
|---|---|---|
| Western Botanicals | Apr 30, 15:50 | |
| Jean-Daniel Dupas | Apr 30, 16:44 | |
| Jens Alfke | Apr 30, 17:08 | |
| Western Botanicals | May 1, 00:14 | |
| Jens Alfke | May 1, 04:30 | |
| Western Botanicals | May 2, 01:49 | |
| Jens Alfke | May 2, 06:58 | |
| Gregory Weston | May 2, 13:37 | |
| Jens Alfke | May 2, 17:22 | |
| Western Botanicals | May 2, 18:32 | |
| Jens Alfke | May 2, 20:03 | |
| Uli Kusterer | May 2, 22:29 | |
| Chris Hanson | May 3, 04:24 |






Cocoa mail archive

