473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Finding a resource leak, is it the background thread or somethingelse?

My application appears to have a recourse leak. When the user starts
a background process, the handle count in Process Explorer (PE) goes
up by about 10, sometime 1 or 2 more, sometimes 1 or 2 less. When the
task is completed, there are somewhere between 4 and 7 handles still
open.

My process is loading images and shrinking them down. I went through
all the code and found some objects that implement the IDisposable
interface which I was not calling Dispose or Close on. Objects such
as AutoResetEvent, Graphic, and Image. I have either encapsulated
them in a using clause or called Dispose on the object before setting
to null and it seems to have no effect.

So I am now wondering where might I find this leak? In the unmanaged
thread handles need to be closed when no longer needed. I am not
seeing any way of cleaning up a managed thread, once it is completed.
Is there some cleanup procedure I am missing or are there other
objects out there that I am not cleaning up correctly?

Are there any good tools out there that might help me in finding this
resource leak?

Cartoper
Mar 18 '08 #1
3 2247
"Cartoper" <ca******@gmail.comwrote in message
news:f6**********************************@u72g2000 hsf.googlegroups.com...
My application appears to have a recourse leak. When the user starts
a background process, the handle count in Process Explorer (PE) goes
up by about 10, sometime 1 or 2 more, sometimes 1 or 2 less. When the
task is completed, there are somewhere between 4 and 7 handles still
open.

My process is loading images and shrinking them down. I went through
all the code and found some objects that implement the IDisposable
interface which I was not calling Dispose or Close on. Objects such
as AutoResetEvent, Graphic, and Image. I have either encapsulated
them in a using clause or called Dispose on the object before setting
to null and it seems to have no effect.

So I am now wondering where might I find this leak? In the unmanaged
thread handles need to be closed when no longer needed. I am not
seeing any way of cleaning up a managed thread, once it is completed.
Is there some cleanup procedure I am missing or are there other
objects out there that I am not cleaning up correctly?

Are there any good tools out there that might help me in finding this
resource leak?

Cartoper


Using Process Explorer you can get a list of the OS handles owned by the
process, so it's not that hard to see whether the "leaked" handles are the
thread handles. My guess is that they are no thread handles, but event
handles.

Willy.

Mar 18 '08 #2
On Mar 19, 6:21*am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
This doesn't mean you are leaking handles, an handle leak would mean that
the handle count keeps increasing without ever going down during the
lifetime of the process, this is not what's happening here I guess, please
correct me if I'm wrong.
Please forgive me, but I thought I cleared stated that BEFORE starting
the thread the handle count was say 309, AFTER the thread starts the
count is above 313, once it stops and time goes by, the handle count
stays at 313. The handle count NEVER EVER returns to 309 once the
thread is started, absolutely NEVER returns. The next time the the
thread is started the count rises above 317 and settles at 317 once
the thread has exited, again NEVER EVER to return to 313 or 309. I am
pretty darn sure this would be considered a handle leak. If it isn't
I most definitly need to find another way to makine a living (like
writing code in good old unmanaged C++).
Also don't forget that the CLR creates it's own OS
objects, the CLR is responsible to release these handles, also don't call
GC.Collect without having a serious reason to do so.
The GC.Collect was for DEBUGGING purposes ONLY. It is quite clearn
that the OS is creating these handles, the only question is, am I not
doing something that will make then get cleaned up?

Cartoper
Mar 19 '08 #3
On Mar 20, 8:24*am, "Willy Denoyette [MVP]"
<willy.denoye...@telenet.bewrote:
***
Not in the menus, but on the tool bar, the sixth button is a toggle - View
Dll's/View Handles. You can also toggle using Cntrl+H/Cntrl/D
***
Sweat, that will hopefully make ALL the difference! I will let you
know.

Cartoper
Mar 20 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
5
by: Barry Anderberg | last post by:
I'm using a tool by Sci-Tech called the .NET Memory Profiler. We have a massive .NET/C# application here and it has been exhibiting memory leak behavior for some time. Attempting to remedy the...
6
by: Mike | last post by:
..NET 1.1 Hi. My C# .NET application has a memory leak - if I leave it running for hours then the system ends up using 500MB+ of virtual memory, which is released immediately when I close the...
8
by: Tor Inge Rislaa | last post by:
Finding the width of a text I need to find the width of a text. When the user change the font in a textbox I want the textbox to fit the text automatically by changing txtMyTextBox.Width...
3
by: Jayme Pechan | last post by:
I was wondering if someone could help me understand why it seems that creating threads using the code below causes handles to seemingly leak. System.Threading.Thread threadRunAsync = new...
10
by: Karl-Inge Reknes | last post by:
Hi, Can anyone tell me how to change a table cells background color or background image in runtime with C#. Karl-Inge
2
by: Paul E Collins | last post by:
Here's some code I'm using: Image img = new Bitmap(32, 16); PictureBox pic = new PictureBox(); pic.Image = img; myForm.Controls.Add(pic); // ... img now goes out of scope ... I'm assuming...
2
by: PimpDaddy | last post by:
Here is the source code of my C++/ME app. When I run it I can use "Windows Task Manager" to see that thread HANDLEs are leaking. #include "stdafx.h" #include <omp.h> public __gc class...
3
by: Lars Uffmann | last post by:
I have this wxWidgets OnButtonClick event handler, that apparently holds a lock on all widgets in my form, but this event handler is supposed to end a thread in the background - while that thread...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.