Dispose pattern: Difference between revisions

Content deleted Content added
Language constructs: add Java "try-with-resources" reference link
Yobot (talk | contribs)
m WP:CHECKWIKI error #61 fixed + general fixes using AWB (8884)
Line 1:
{{Unreferenced|date=May 2009}}
{{redirect|Dispose||Disposal (disambiguation)}}
{{Refimprove|date=February 2013}}
In [[computer programming]], the '''dispose pattern''' is a [[design pattern (computer science)|design pattern]] which is used to handle resource cleanup in [[runtime environment]]s that use [[automatic garbage collection]]. The fundamental problem that the dispose pattern aims to solve is that, because objects in a garbage-collected environment have [[finalizer]]s rather than [[destructor (computer science)|destructors]], there is no guarantee that an object will be destroyed at any deterministic point in time. The dispose pattern works around this by giving an object a [[method (computer science)|method]] (usually called <code>Dispose</code> or similar) which frees any resources the object is holding onto.
 
Line 59:
</source>
 
The [[Java (programming language)|Java]] language introduced a new syntax called <code>try</code>-with-resources in Java version 7 .<ref>Oracle Java tutorial: [http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html The try-with-resources Statement]</ref>. It can be used on objects that implement the AutoCloseable interface (that defines method close()):
<source lang="java">
try ( OutputStream x = new OutputStream(...) ){