473,385 Members | 1,356 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,385 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
over,
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?

[code]
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()
{
InitializeComponent();

// 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,
(uint)ResourceType.Gdi);

// loop
while (m_isRunning)
{
CreateDisposeTreeView();
++m_treeViewCount;
}

// 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",
m_treeViewCount,
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;
m_pnlContainer.Controls.Add(tvw);

// do some gui processing
Application.DoEvents();

// dispose
m_pnlContainer.Controls.Remove(tvw);
tvw.Dispose();
tvw = null;

// do some gui processing
Application.DoEvents();

}

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

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

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

#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)
///
[DllImport("user32.dll")]
private static extern uint GetGuiResources(IntPtr hProcess, uint
uiFlags);

private enum ResourceType
{
Gdi = 0,
User = 1
}

[DllImport("kernel32.dll")]
private static extern IntPtr GetCurrentProcess();

[DllImport("psapi.dll")]
private static extern int GetProcessMemoryInfo(IntPtr hProcess, out
PROCESS_MEMORY_COUNTERS counters, int size);

[StructLayout(LayoutKind.Sequential, Size=40)]
private struct PROCESS_MEMORY_COUNTERS
{
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;
}

#endregion

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 4723

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

Similar topics

3
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...
1
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 ...
1
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...
1
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...
1
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...
1
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...
2
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...
2
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...
3
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.