472,354 Members | 1,150 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

TreeView checkbox gdi memory leak

hi there i've a test program that creates a treeview and destroys it over and
i keep track of the gdi object count for the process and see if they are ok.

However when i switch on checkboxes for my test app i get a gdi handle leak

anyone got any ideas on this one?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace TreeViewMemoryLeak
public partial class Form1 : Form
public Form1()

// get process
m_processHandle = GetCurrentProcess();

// update status
OnTimer_Tick(this, null);

private void OnStartStop_Click(object sender, EventArgs e)
// invert state
m_isRunning = !m_isRunning;

// disbale if running
m_chkUseCheckboxes.Enabled = !m_isRunning;
m_btnStartStop.Text = (m_isRunning) ? "Stop loop" : "Start
create / dispose loop";

// running?
if (m_isRunning)
// reset
m_lblSummary.Text = "";
m_treeViewCount = 0;
m_initialGdiCount = GetGuiResources(m_processHandle,

// loop
while (m_isRunning)

// how many GDI objects per tree view?
uint gdiObjects = GetGuiResources(m_processHandle,
(uint)ResourceType.Gdi) - m_initialGdiCount;
m_lblSummary.Text = string.Format(
"{0} TreeViews were created and disposed with a {1:0.0}
GDI objects leak per TreeView",
gdiObjects / (float)m_treeViewCount);

private void CreateDisposeTreeView()
// create
TreeView tvw = new TreeView();
tvw.Location = new Point(20, 20);
tvw.Size = new Size(100, 100);
tvw.CheckBoxes = m_chkUseCheckboxes.Checked;

// do some gui processing

// dispose
tvw = null;

// do some gui processing


private void OnTimer_Tick(object sender, EventArgs e)
// update status bar
if (m_processHandle != IntPtr.Zero)
// memory
GetProcessMemoryInfo(m_processHandle, out counters, 40);
m_sslMemory.Text = string.Format("Memory usage: {0:#,##0}
KBytes", counters.WorkingSetSize / 1024);

// gdi
m_sslGdi.Text = string.Format("GDI Objects: {0}",
GetGuiResources(m_processHandle, (uint)ResourceType.Gdi));

// objects
m_sslObjectCount.Text = string.Format("TreeViews: {0}",

#region Win32 API functions

/// uiFlags: 0 - Count of GDI objects
/// uiFlags: 1 - Count of USER objects
/// - Win32 GDI objects (pens, brushes, fonts, palettes, regions,
device contexts, bitmap headers)
/// - Win32 USER objects:
/// - WIN32 resources (accelerator tables, bitmap resources,
dialog box templates, font resources, menu resources, raw data resources,
string table entries, message table entries, cursors/icons)
/// - Other USER objects (windows, menus)
private static extern uint GetGuiResources(IntPtr hProcess, uint

private enum ResourceType
Gdi = 0,
User = 1

private static extern IntPtr GetCurrentProcess();

private static extern int GetProcessMemoryInfo(IntPtr hProcess, out
PROCESS_MEMORY_COUNTERS counters, int size);

[StructLayout(LayoutKind.Sequential, Size=40)]
public int cb;
public int PageFaultCount;
public int PeakWorkingSetSize;
public int WorkingSetSize;
public int QuotaPeakPagedPoolUsage;
public int QuotaPagedPoolUsage;
public int QuotaPeakNonPagedPoolUsage;
public int QuotaNonPagedPoolUsage;
public int PagefileUsage;
public int PeakPagefileUsage;


private IntPtr m_processHandle = IntPtr.Zero;
private bool m_isRunning = false;
private int m_treeViewCount = 0;
private uint m_initialGdiCount = 0;
Nov 23 '05 #1
0 4659

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

Similar topics

by: feel | last post by:
Goin' crazy with this recursive function ported from delphi... I send a string like DirA/ DirB /DirC but i get in the treeView each one in a new node.Cant get the child node....!! -DirA -DirB...
by: kiran | last post by:
I cratee a form to meet the fallowing requirement. 1. If any node is selected the corresponding checkbox should be checked 2. If any checkbox is clicked the corresponding node should be selected ...
by: Srinivasa Raghavan | last post by:
Hi All, I have some doubts on the Treeview control and Form Authentication 1) will Form Authentication work if cookies are disabled. 2) I have problem in the following code (TreeView...
by: nicholas | last post by:
I am using Obout TreeView: www.obout.com I would like to implement a page to add and remove categories to a product with the Obout Treeview with checkboxes. Does anyone allready did this and...
by: Ronen | last post by:
Hi, Does anyone experienced memory leak in Iexplore.exe when use treeview (MS IE Controls? I'm have tested this with a simple web page with a few tree nodes generated on the server. Then I...
by: Sun | last post by:
Hi All, I am facing a prob with treeview with check boxes When ever a javascript funtion is associated with Treeview, I am not able to retrice the Values of checkboxes in the tree. When no...
by: engwar1 | last post by:
I'm a .Net newbie and have started writing a Windows Forms application to assist me in choosing files/directories to move from one drive to another. Basically what I want is something like the...
by: Manikandan | last post by:
Hi, I'm using .NET1.1. I have a windows form with two controls 1.Treeview 2.Checkbox I added the items into tree view, the user selects the item in treeview. When i click the item in...
by: prpradip | last post by:
In article, I found that there is memory leakage in TreeView with checkboxes for .net 1.1 Found GDI leak in TreeView (anyone know about it?) and .net 2.0...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

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.