473,804 Members | 3,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2277
"Cartoper" <ca******@gmail .comwrote in message
news:f6******** *************** ***********@u72 g2000hsf.google groups.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.bewro te:
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.bewro te:
***
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
1386
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 Li (likong@email.com)
5
2109
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 problems I am employing the aforementioned software in trying to track down the problems. After an hour or so of program execution, a snapshot of the managed heap shows 27,025 BinaryReader objects as having been garbage collected but never...
6
461
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 app. Now, I thought this would be impossible with automatic garbage collection, but it seems this is not the case. The application is threaded and all work is done within spawned threads. No
8
1438
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 according to the actual width of the text. It can also be useful to know the actual height when using multiline textbox. Is this possible? TIRislaa
3
7962
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 System.Threading.Thread(RunFunc); threadRunAsync.Start(listParams); I have to use ThreadPools in order to avoid the handle leaks. System.Threading.ThreadPool.QueueUserWorkItem(new
10
5705
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
1730
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 that, when myForm gets closed, then pic is Disposed (as part of the Controls collection) and at the same time Disposes of the
2
2549
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 TestClass { public: void ThreadProc()
3
2380
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 is supposed to update widget content. So if I want to wait for the thread to end in the event handler, I have 2 threads waiting on each other - with the one in the background waiting to access the widget content. My current workaround is to...
0
9571
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10318
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.