Since exceptions in Objective-C are full featured objects (which don't have to be derived from NSException), it is legit for a code monkey to wonder when are the exceptions ... well you know, released. From what I have seen so far in Apple documents and from (most) code samples I see on the web, it appears as exception object are released automagically at some point ... but are they really? Having derived Cocoa's exception class to add an origin field to it, I also added to my class an implementation of the
As you will have guessed (easy since otherwise I will not be blogging about it), I found out that the method was not been called unless I explicitly send a
dealloc
method (so that I could release the origin string). For good measure, I also added a printf
statement just to verify that the method was been called (e.g I could have goofed up the signature).As you will have guessed (easy since otherwise I will not be blogging about it), I found out that the method was not been called unless I explicitly send a
release
or autorelease
message to the exception object within the catch block ... (!!?) A quick search on the web didn't yield more details, except for an blog post by Chris Hanson showing an autorelease
message been sent from a finally block for a caught exception (however that occurrence is due to him retaining the exception in the catch block, so not really relevant to the case at hand). I'll have to dig this further ...
No comments:
Post a Comment