Questions tagged [resource-leak]
208 questions
69
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
- 8,562
- 4
- 31
- 52
31
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…

Niek van der Linden
- 347
- 1
- 4
- 9
22
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
- 345
- 1
- 4
- 13
21
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,305
- 3
- 16
- 30
18
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
- 181
- 1
- 1
- 8
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
- 41,386
- 23
- 126
- 155
15
votes
2 answers
Do asynchronous context managers need to protect their cleanup code from cancellation?
The problem (I think)
The contextlib.asynccontextmanager documentation gives this example:
@asynccontextmanager
async def get_connection():
conn = await acquire_db_connection()
try:
yield conn
finally:
await…

Maxpm
- 24,113
- 33
- 111
- 170
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
- 48,038
- 36
- 121
- 139
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
- 28,701
- 14
- 75
- 97
12
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
- 4,030
- 9
- 41
- 66
12
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
- 25,628
- 5
- 56
- 89
12
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
- 7,101
- 1
- 41
- 51
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,666
- 4
- 26
- 42
9
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
- 16,456
- 10
- 90
- 156
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,500
- 3
- 39
- 48