, " " ? ( , , , auto_ptr, ), , :
int function blah(arg1, arg2)
allocate resource
if early failure detection
return failure_status
... much later...
release resource // oh rats! resource didn't release
return success_status
, . , . ( ). ++ delete, auto_ptr, , auto_ptr , .
, Python, , , , . , CPython (jython IronPython, ), , , - . try/finally:
int function blah(arg1, arg2)
allocate resource
try:
if early failure detection
return failure_status
... much later...
return success_status
finally:
release resource // always releases no matter what
Python "":
int function blah(arg1, arg2)
allocate resource
with context_manager(resource): // releases on exit from 'with'
if early failure detection
return failure_status
... much later...
return success_status
, , , , , .