Questions tagged [resource-leak]

191 questions
63
votes
4 answers

Why is Files.lines (and similar Streams) not automatically closed?

The javadoc for Stream states: Streams have a BaseStream.close() method and implement AutoCloseable, but nearly all stream instances do not actually need to be closed after use. Generally, only streams whose source is an IO channel (such as those…
MikeFHay
  • 7,264
  • 4
  • 24
  • 43
28
votes
4 answers

Scanner is never closed

I'm working on a game and I came across a little problem with my scanner. I'm getting a resource leak scanner never closed. But I thought my scanner was working before without closing it. But now it ain't. Anyone can help me out here? import…
20
votes
2 answers

Does DataAdapter.Fill() close its connection when an Exception is thrown?

I am using ADO.NET (.NET 1.1) in a legacy app. I know that DataAdapter.Fill() opens and closes connections if the connection hasn't been opened manually before it's given to the DataAdapter. My question: Does it also close the connection if the…
motto
  • 1,217
  • 3
  • 16
  • 30
19
votes
3 answers

What's the upper limit on GDI objects for one process in Windows 7?

Have an application with a GDI leak that will eventually hit 10,000 allocated GDI objects and crash. I tried increasing the GDIProcessHandleQuota to 20,000, but the program still crashed when it reached 10,000 objects. We're currently working on…
Micky
  • 315
  • 1
  • 4
  • 13
16
votes
6 answers

Do I need to call Close() on a ManualResetEvent?

I've been reading up on .NET Threading and was working on some code that uses a ManualResetEvent. I have found lots of code samples on the internet. However, when reading the documentation for WaitHandle, I saw the following: WaitHandle…
Kevin Hakanson
  • 38,937
  • 23
  • 119
  • 148
16
votes
3 answers

Resource leak warning in eclipse

In Eclipse I received a warning Resource leak: 'ps' is not closed at this location that I don't understand. In my Java code I declare the "ps" as a Prepared Statement and I use (and close) it many times. Then I've the following sequence: try { …
Reto Strub
  • 161
  • 1
  • 1
  • 8
13
votes
17 answers

.NET Resource Leak Gotchas

There are several ways that developers can get caught out by unintentional resource leaks in .NET. I thought it would be useful to gather them in one place. Please add yours with one answer per item, so the best get voted up :)
Thomas Bratt
  • 40,822
  • 34
  • 113
  • 133
12
votes
3 answers

RenderTargetBitmap GDI handle leak in Master-Details view

I have an app with a Master-Details view. When you select an item from the 'master' list, it populates the 'details' area with some images (created via RenderTargetBitmap). Each time I select a different master item from the list, the number of GDI…
Wilka
  • 26,494
  • 13
  • 71
  • 94
11
votes
8 answers

Hunting down EOutOfResources

Question: Is there an easy way to get a list of types of resources that leak in a running application? IOW by connecting to an application ? I know memproof can do it, but it slows down so much that the application won't even last a minute. Most…
Marco van de Voort
  • 24,435
  • 5
  • 52
  • 86
11
votes
2 answers

Why call Dispose() before main() exits?

My .net service cleans up all its unmanaged resources by calling resourceName.Dispose() in a finally block before the Main() loop exits. Do I really have to do this? Am I correct in thinking that I can’t leak any resources because the process is…
s d
  • 2,546
  • 3
  • 24
  • 40
10
votes
1 answer

Force warning when class is not closed

When I work with IO classes like java.util.Scanner or java.io.BufferedReader, Eclipse displays a warning Resource leak: 'suchAndSuch' is never closed. How can I make Eclipse display this warning for my own class when it is not closed? What I want…
jpyams
  • 2,949
  • 3
  • 29
  • 56
9
votes
3 answers

Is KillTimer necessary?

I use SetTimer API and I see a lot of code like this: case WM_DESTROY: // Destroy the timer. KillTimer(hwnd, IDT_TIMER); PostQuitMessage(0); break; Do I have to call KillTimer or the system will automatically free resources on…
Sergey Podobry
  • 6,627
  • 1
  • 37
  • 47
8
votes
3 answers

Using statement around dialog form to ensure garbage collection

We have a Windows Forms application that contains thousands of forms. Many of these are temporarily displayed as dialogs via the ShowDialog() method. This application has been around for years and we've discovered that many of the forms are not…
Avalanchis
  • 4,243
  • 2
  • 34
  • 46
8
votes
4 answers

What can cause section handle leaks?

This is a follow-up question to my previous question. As suggested in this answer to my previous question, I used ProcessExplorer to analyze a list of handles that my application is using to find a handle leak. The handles that are leaking are of…
jpfollenius
  • 15,826
  • 9
  • 83
  • 148
8
votes
2 answers

Do I need a WOW64 dump for GDI Handle analysis?

I'm debugging a potential GDI Handle Leak. Thanks to @Alois Kraus, there is a WinDbg script which performs a handle count. From my debugging sessions, especially for .NET, I find that usually, it's better to have 32-bit dumps of 32-bit processes and…
Thomas Weller
  • 43,638
  • 16
  • 101
  • 185
1
2 3
12 13