Dispose pattern: Difference between revisions

Content deleted Content added
Language constructs: The C#, Python, and Java examples are for resources held in one block of code. Is there a citation for the viral aspect where object A holding a reference to disposable object B also needs to be disposable?
Rephrase paragraph about Python "with" statement, change plain link to reference
Line 55:
</source>
 
Similarly, the [[Python (programming language)|Python]] language has a <code>with</code> statement that can be used to similar effect with a ''context manager'' object. The ''context manager protocol'' impliesrequires implementing <code>__enter__</code> and <code>__exit__</code> methods which get automatically called by the <code>with</code> statement construct, to facilitateprevent notduplication needingof exceptioncode handlingthat clauseswould suchotherwise asoccur with the <code>try</code>/<code>finally</code> topattern.<ref>{{cite cleanupweb resource|author=[[Guido allocationsvan Rossum]], etc.Nick (seeCoghlan [|date={{date|2011-06-13}} |title=PEP 343: The "with" Statement |publisher=Python Software Foundation |url=http://legacy.python.org/dev/peps/pep-0343/ PEP 343]):}}</ref>
<source lang="python">
with resource_context_manager() as resource: