Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on what you call performance. I'll assume you're speaking of overall performance, meaning that memory consumption, speed, and the like are all important.</p> <p>It depends, too, on the resource used. Some resources (e.g. file handles) are recovered when the process exits, so the leak will only be a problem when executing. Others (like server or database connections) could remain leaking even after your application execution. Others (like mutexes, etc.) should be released as soon as possible.</p> <p>Now, the consequences depend on the resource. If the resource is a native object in the same process, then leaking it will probably leak the associated memory. If the resource is a mutex you locked but failed to unlock, then you are probably about to deadlock your application. If the resource is a connection, the server will keep that connection open even after you stopped using it. If the resource is a file, it could stop other applications (or even your own application) to access it again.</p> <p>In the end, while some resources could be leaked, other shouldn't. As far as I am concerned, no resource should be leaked, ever, but YMMV.</p> <p>So you should make an habit of always correctly releasing the resources you acquired (memory, files, connections, mutexes, etc.), no matter the perceived importance of that resource. Doing so will train you in the right coding patterns (and mindset).</p> <p><a href="https://en.wikipedia.org/wiki/Resource_Acquisition_Is_Initialization" rel="nofollow">RAII</a> and <a href="https://en.wikipedia.org/wiki/Exception_safety#Exception_safety" rel="nofollow">Exception Safety</a> are the keyword you're searching for if you want to explore the notions.</p> <p>For C#, the <a href="http://msdn.microsoft.com/en-us/library/b1yfkh5e.aspx" rel="nofollow">Dispose pattern</a> (IDisposable interface, and the finalizer) and the <code>using</code> keyword will be needed. Another solution is to use the <code>finally</code> class of a <code>try</code>/<code>finally</code> to free your resource, but this is difficult to maintain correctly.</p> <p>In Java, you'll need Java 7 (IIRC), and use the AutoCloseable interface and the "<a href="http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html" rel="nofollow">try-with-resources</a>" statement. As in C#, you can use the <code>finally</code> class of a <code>try</code>/<code>finally</code> to free your resource, with the same problems.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload