How can I do something when a runloop event is done processing?

Posted by quixoto on Stack Overflow See other posts from Stack Overflow or by quixoto
Published on 2010-06-12T22:29:20Z Indexed on 2010/06/12 23:02 UTC
Read the original article Hit count: 230

Filed under:
|

I have some processing in my Cocoa app that sometimes ends up calling through a hierarchy of data to do a bunch of work as the result of an event. Each small piece creates and destroys some resources. I don't want those resources around most of the time, but I would like to find a smart way of creating them before all the work and killing them at the end.

Short of making those buffers etc available globally from the "parent" or elsewhere, is there a way to know locally in some code when an event loop run has ended? Then I could create them if they're not there, and keep them until the run loop ends, reusing them for any subsequent calls before that time.

EDIT: I'm not looking for suggestions on how to restructure my code, which I may do anyways. This issue just brought up the question for me of how to know when the runloop is done. If I were writing in, I dunno, Javascript, I'd use a setTimeout with zero to accomplish end-event cleanup. I suppose an NSTimer with an interval of zero might accomplish this too, but wondering if there's something cleaner.

Thanks.

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nsrunloop