Question

I am trying to release resources allocated in daemon process at the end of it or if someone quits the process.

Lets say,

int main(int argc, const char * argv[])
{
    Controller *controller = [[Controller alloc] init];
    [controller allocateresources];

    [[NSRunLoop currentRunLoop] run];

    [controller release];

    return 0;
}

Here Controller release will not be called. Quit [SIGTERM Signal] just terminates the runloop. How can I release resources allocated in class Controller at the end of application?

EDIT: I understand that system will claim resources back. The thing, I am trying to solve is something like cross process cooperative locks.

Was it helpful?

Solution

I don't think there is really a guarantee that you will return from the -run method. So you shouldn't rely on this to free the resources. There are other ways to do it. For example, a really low-level solution would be to implement an atexit handler

https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man3/atexit.3.html

and do the necessary freeing of the lock there.

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