I have a method that selects an object and then releases it at the end. Between them, the method calls another method that can throw an exception, and the exception is likely to be caught by the method that calls my method. If this happens, the object will never be released (or will it be?). How to prevent this?
You can always automatically release it before calling methods that can be selected - this way you can be sure that it will be released, otherwise an exception will be thrown.
If for some reason this is unreasonable, you can do the release in block @finally 1
@finally
A @finally , , .
, @finally @catch :
@catch
Resource *resource = [[Resource alloc] init]; @try { [obj someMethodThatMayThrow]; } @finally { [resource release]; }
Cocoa, . , , :
Cocoa, API
, , , undefined
Mac OS X iOS ; , , . , , , , .
, iOS ( , ). , @finally , @finally .
Source: https://habr.com/ru/post/1750934/More articles:Get a list of available types of Drupal - phpHow to format date from timestamp in PHP? - phpImplementing the life cycle of an Android game thread - javaWindows Phone 7 Development, how different is it from version 6.x? - windows-mobileHow to check if the variable has "http: //", and if not, add it? - phpwhy using "\" shows an error in jython - jythonCreate a kext to replace switch keys with a key to lock caps or a function key (fn) - osx-snow-leopardHow to replace all values in a hash with a new value? - ruby | fooobar.comorg.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions - springChanging file metadata in Python - pythonAll Articles