I have lots of methods like this:
-(NSObject *)theObject
{
static NSObject *obj = nil;
static dispatch_once_t onceToken = 0;
dispatch_once(&onceToken, ^{
obj = [[NSObject alloc] init];
atexit_b (^{
[obj release], obj = nil;
});
});
return obj;
}
I think the original purpose of using atexit_b
was to be a good citizen and release the memory used just before the application ends :). However, AFAIK, the runtime will re-collect all memory when my application exits (or terminated, etc) anyway.
Can I always assume this? or perhaps it depends on the OS/runtime/some implementation?
In my particular case, I have several (lets say a few dozens) of atexit_b
calls all around the application, so it means some amount of memory is being used to do something unneeded.
Is this true? If so, then does it mean I don't need atexit_b calls?