views:

34

answers:

1

I have a given line of code, after which none of my own code lines should get executed (not in the same "event loop").

How do I configure the Xcode debugger to catch instances in which some of my own code indeed does get executed after this given line of code?

If it's not possible to filter by the "event loop", can I filter it down to, say, "within 2 seconds after"?

+1  A: 

If you wanted to be really convoluted about it, you could rely on knowing that an autorelease pool is drained at the end of the event loop, and create a class which overrides -retain and -release, and when the retain count (which I would recommend an ivar for) hits zero, set a flag, raise the retain count to one again, and somehow get it in the next autorelease pool to be created for the new event loop. At the beginning of each method you want to ensure only happens before some line of code, check that the flag is raised in the class overriding -retain/release, and if it isn't, break/throw error/log/etc. (A macro would probably make shorten the code, and you could conditionally define it for debug builds.) Then, right after the line that you want to ensure none of your code comes after, reset the flag. This way, any code that is entered after this line will see the unset flag and log/fail/tell you about it, and the flag is reset after every event loop.

Some other things: You should either define +retain/+release and add the class object to the autorelease pool with +[NSAutoreleasePool addObject:], or make it a singleton object, seeing as the flag would have to be accessible without really wanting to pass this object around. Second of all, I seem to have neglected how to insert the class/singleton into the autorelease pool for the next loop, after this one is drained. This is because it is the hardest part, and I have no real idea, but I have the feeling [self performSelector:@selector(autorelease) afterDelay:0] would work.

Jared P
Alas, I'm using garbage collection. I assume checking the autorelease pool won't work in that case, right? Anyway, Joshua is right about the relationship of this problem to the other problem; see the other problem for more context.
Enchilada