handle-leak

Handle leaks with .NET System.Threading.Thread class

佐手、 提交于 2020-01-06 06:55:39
问题 I've a problem that number of Handles in my app is continuously growing. I did the debugging and recognize that this is caused by System.Threading.Thread class which is used for some routine. To simplify the debugging I’ve created a sample .NET application: ... private void button1_Click(object sender, EventArgs e) { Thread t = new Thread(DoWork); t.Start(); } public void DoWork(object parameter) { // Do something... } ... Each time I’m clicking the button, a thread is created using System

Determine number of GDI handles and USER objects

夙愿已清 提交于 2019-12-23 10:14:20
问题 We developed a small test suite for our Windows Forms UI rendering engine which allows to measure performance and detect memory leaks while running test cases in an automated manner. Now we would like to check for handle leaks as well. On the desktop platform we can use this code: [DllImport("User32")] private extern static int GetGuiResources(IntPtr hProcess, int uiFlags); using (var process = Process.GetCurrentProcess()) { var gdiHandles = GetGuiResources(process.Handle, 0); var userHandles

CreateFileMapping, MapViewOfFile, handle leaking c++

人盡茶涼 提交于 2019-12-12 16:09:19
问题 Background: I am trying to create a memory mapped file that can be accessed by multiple processes. In the below code I only put in the code that pertains to the question I currently have to make things simpler. According to msdn I should be able to create a filemap, map the view of the file and close the handle I received from CreateFileMapping and the MapViewOfFile will keep my FileMap alive. The FileMap should be still accessible until I UnmapViewOfFile. MSDN: CreateFileMapping function

How to avoid leaking handles when invoking in UI from System.Threading.Timer?

↘锁芯ラ 提交于 2019-11-30 19:34:24
It seems like calling Invoke on a winforms control in a callback from a System.Threading.Timer leaks handles until the timer is disposed. Does anyone have an idea of how to work around this? I need to poll for a value every second and update the UI accordingly. I tried it in a test project to make sure that that was indeed the cause of the leak, which is simply the following: System.Threading.Timer timer; public Form1() { InitializeComponent(); timer = new System.Threading.Timer(new System.Threading.TimerCallback(DoStuff), null, 0, 500); } void DoStuff(object o) { this.Invoke(new Action(() =>

How to avoid leaking handles when invoking in UI from System.Threading.Timer?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 03:53:14
问题 It seems like calling Invoke on a winforms control in a callback from a System.Threading.Timer leaks handles until the timer is disposed. Does anyone have an idea of how to work around this? I need to poll for a value every second and update the UI accordingly. I tried it in a test project to make sure that that was indeed the cause of the leak, which is simply the following: System.Threading.Timer timer; public Form1() { InitializeComponent(); timer = new System.Threading.Timer(new System