.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Memory leak on binding to a WPF TreeView

Posted By:      Posted Date: September 14, 2010    Points: 0   Category :WPF
We're having an issue with a TreeView hanging onto a viewmodel set that has been bound to it. We have a static treeview on the main window, and reset its ItemsSource to Nothing or a new viewmodel when new things need to be displayed. The problem seems to be that it's hanging onto the first item that it was bound to, even after the ItemsSource is set to nothing. The connection seems to be through some strange unknown binding that's in the EffectiveValues collection of the TreeView.   I was able to repro this in a test project, so I'll post the simplified code:   TreeView templates:   <Window.Resources> <HierarchicalDataTemplate DataType="{x:Type local:ParentViewModel}" ItemsSource="{Binding ChildVMs}"> <TextBlock Text="{Binding Name}"/> </HierarchicalDataTemplate> <DataTemplate DataType="{x:Type local:ChildViewModel}"> <TextBlock Text="{Binding Name}"/> </DataTemplate> </Window.Resources>   ViewModel definitions: (Shared Function to generate the itemssource for the treeview)   Public Class ParentViewModel Public Shared counter As Integer = 0 Public Shared Function GenerateViewModel() As List(Of ParentViewModel) Dim pvm As New ParentViewModel With {.Name = "Parent" & counter} ' Unique name pvm.ChildV

View Complete Post

More Related Resource Links

Memory leak?


I’m not sure how I should consider my problem. I’m developing workflow with VS 2008 for MOSS 2007. I’ve created simple method which remove security group “MyGroup” from the item. And it seems that it works:

private void UsunDziedziczenieUprawnien_ExecuteCode(object sender, EventArgs e)


            using (SPSite site = new SPSite (workflowProperties.SiteId))

WmiPrvSE.exe causes a huge memory leak in SQL server 2008 R2, why?

My OS is windows server 2008 r2 data center 64 bit and my SQL server is server 2008 R2. The problem is when I open sql server, the WmiPrvSE.exe process consumes 20 - 60kbs every second. Several hours later, it eats up at least 200mbs memorry and this process seems like it will never stop. Can any experts give me some ideas to fit this mess? PS: My mainboard is Asus striker II formular, cpu is intel quad-core. Also, all my software are updated to latest version.

Binding the sharepoint treeview to the quick launch data source

Is there any way i can bind the sharepoint treeview navigation to the same datasource as the quick launch bar? I'm trying to create a consistent navigation structure within a 4-site deep structure so the quick launch bar is rather clunky to use, but the treeview picks up on document libraries i don't want it to (i only want it to show subsites and pages).

Binding to the TreeView control

My TreeView controls is rendering CheckBoxes on Leaf nodes. I want to bind to those nodes the ID of the underlying data item. I am not sure I can do this declaratively or if I need to hook up to the TreeNodeDataBound event. If the latter, how would I go about achieving this?   _hector

InteropBitmap memory leak

Goal : Create a scrolling wave form that has a low overhead (WPF) Challenges : Huge bitmaps are not accepted by Image.Source Smaller (but still very big bitmaps) are accepted but overall UX is terrible. Memory conservation Scrolling must be at 60fps Problems encountered : Used GPU memory amount is insane ! (400 to 800 Mb each 10 seconds) So here's what I did : I am rendering that bitmap through an Image.Source that I created with Imaging.CreateBitmapSourceFromMemorySection (which type is InteropBitmap). I have loaded that big bitmap in memory and every time I need to update, I do a CopyMemory then I do InteropBitmap.Invalidate(), so far it's perfect and performance is excellent. That particular type of BitmapSource is said to be the fastest, and it is actually; but after some profiling, it litterally eats GPU memory, as said above. It seems that InteropBitmap never recycles GPU memory, or caches it, I don't know... On my Win7 x64 machine, I have 4Gb of which up to 1.5Gb can be used by the GPU. (Laptop is a Thinkpad T61p with dual-core at 2.5Ghz and a Quadro FX570M with 256Mb) My first and safer solution was to use a WriteableBitmap which works good but no 60 fps here, What do you suggest ? Shall I go WinForms for required performance ?   Thanks for your help !

Binding a treeview to a LinqToSQL class...


Hi all,

I have a LinQtoSQL class which encapsulates a table with the following relationship:

Id (int)
Parent ID(int)
Name (string)

Here, the parent ID is the id of another row int he same table. So, the table could look like:

1, null, grandpa
2,1, mom

What I want to do is the create a treeview that binds to the table so that it looks like this:


Also, I should be able to add or delete nodes/rows...

Any ideas on how to do this? Is this even possible without writing the code to do all the population and the edit etc?





SharePoint memory leak (8l1n)

hi , I'm annoied with the memory leak problem these days. the following text is copied from the ULS log. Does anyone can read this?  or pick up some clues out of it?

it's high appreciate for your help!

8l1n High     An SPRequest object was not disposed before the end of this thread.  To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it.  This object will now be disposed.  Allocation Id: {BE9269D2-BE0D-4A94-BBD9-71FD642892F2}  This SPRequest was allocated at    at Microsoft.SharePoint.Library.SPRequest..ctor()     at Microsoft.SharePoint.SPGlobal.CreateSPRequestAndSetIdentity(Boolean bNotGlobalAdminCode, String strUrl, Boolean bNotAddToContext, Byte[] UserToken, String userName, Boolean bIgnoreTokenTimeout, Boolean bAsAnonymous)     at Microsoft.SharePoint.SPWeb.InitializeSPRequest()     at Microsoft.SharePoint.SPWeb.EnsureSPRequest()     at Microsoft.SharePoint.SPWeb.get_Request()     at Microsoft.SharePoint.SPListCollect... 
09/21/2009 13:16:35.11* w3wp.exe (0x1780)                        0x13D0 Windows SharePoint Services    General                        8l1n High     ...ion.EnsureListsData(Guid webId, String strListName)     at Microsoft.SharePoint.SPListCollection.EnsureListsData(String strListName)     at Microsoft.SharePoint.SPListCollection.ItemByInternalName(Strin

Binding a TreeView to a collection of objects



I want to achieve this:


through data binding. That is, I've got this collection of objects of the same class (currently stored in a ArrayList), and I want to display them in a treeview, so that when you expand them you can see the values of their attributes.

Is it possible to do it via DataBinding?





Binding a Treeview to an exception...

I'm not too familiar with Hierarchal DataTemplates yet, but here's what I want to do. 

I have a message box that has a small expander on the bottom with a treeview inside.  I want to hook the treeview up so that during runtime when an error occurs it can be caught, loaded into this treeview and displayed (including all the inner exceptions). 

How would I go about doing this? 

I'm fairly familiar with wpf and I can get everything into the message box correctly it's just the final display that I can't do yet. Also, I'm using VS 2010 Ultimate Beta 2.  Thanks in advance!!

VS 2010 memory leak?


It happens frequently when I try to copy & paste code inside VS 2010 with following message:

insufficient available memory to meet the expected demands of an operation at this time, possibly due to virtual address space fragmentation. Please try later.

and I check the memory usage with taskmanager on my computer. It is fine.

In order fix it, I need to close VS 2010 and restart again.

So is it a memory leak or can be fixed in some way?

WPF TreeView Binding


Hello All,

I am having a heck of a time trying to get a TreeView control bounded to a List which is a member of Class which is a member of the MainWindow. Here is a contrived example similar to what I am trying today. Can anyone help me bind so that the Server Names show as Items in the TreeView. This would be a huge help.


Custom Classes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SystemsManagement
    public class ServerManager
        public List<Server> Servers { get; private set; }

        public ServerManager()
            Servers = new List<Server>();

            Servers.Add(new Server("Server1"));
            Servers.Add(new Server("Server2"));


    public class Server

WPF Treeview - Binding to a collection with different depths, and styling differently


Apologies for the long post -- Read a few threads about this, but still find it hard to implement. Basically, I have a collection of objects, defined as:

public class LibData
  public string Name { get; set; }
  ObservableCollection<LibObject> _list;
  public ObservableCollection<LibObject> List { get { return _list; } }

  public LibData(string name, LibDataType type)
    this.Name = name;
    _list = new ObservableCollection<LibObject>();

Workflow Designer 4.0 Load() Performance Issue: possible memory leak?


Hello everybody,

I am trying to implement a workflow designer in a windows form application and use the same designer to view different workflows. However, I found the program became slower and slower after loading several workflows.

my steps are as follows:

1. create a wpf user control WFDesigner to package the workflowdesigner;

2. In the user control  WFDesigner , implement a InitiateDesigner method which create a new workflowDesigner instance each time called. I suppose the old workflowDesigner instance would be collected by GC;

3. create a winform application and install the user control created on step 2 to an element host, and put the element host on the form. 

4. add two buttons for test: one will execute  WFDesigner.InitiateDesigner() once and the other will execute it 100 times.

ResXResourceReader memory leak?


I have occasion in my program to compile some CSharp code on the fly, with embedded resources from a .resx file. To do this, I use a System.Resources.ResXResourceReader to read the ResX file and a System.Resources.ResourceWriter to create the binary resource file. However, when I step through the code, I find that ~15MB of memory gets taken up when the ResXResourceReader reaches a Node whose value is a Bitmap, and that memory doesn't get freed even if I explicitly dispose the Bitmap. The ResXResourceReader is getting disposed (it's declared in a using statement). How can I keep this memory leak from happening? Here's the code where I read through the ResX file:


using (System.Resources.ResourceWriter Writer = new System.Resources.ResourceWriter(FileName = System.IO.Path.GetTempPath() + ClassName + ".resources"))

using (ResXResourceReader ResXReader = new ResXResourceReader(this.ResourceFileName))
                foreach (System.Collections.DictionaryEntry Node in ResXReader)

Nonstandard Treeview Binding


I am currently binding a Treeview to an Entity Framework objectset, which is working just fine. However I would like to organize the nodes in the treeview differently.

For example, if I bind so the root nodes represent the Students collection and the leaf nodes are that student's Subjects collection, that is just fine, but can I change the arrangement so that there are two root nodes, say Male and Female students, according to a property of the Student, and underneath those, the leaf nodes are say Bob, Dave, Steve under the Male root. And Jane, Sheila and Gertrude under the Female root?

In other words, instead of binding to Students and a collection belonging to Students, can I set up the treeview in such a way that the root nodes are manually specified, and the leaf nodes are under the correct root based on a property of the Students?

Thanks for any advice.

Is this a Memory Leak?



I am developing an app using the MVVM model and I am doing something which I think might create a memory leak.

Basically I have a master ViewModel which contains an ObservableCollection<Child1ViewModel>. Then, each Child1ViewModel contain an ObservableCollection<Child2ViewModel> and so on. I have 4 layers like that.

Each layer contains a reference to its parent. I added a "Delete Self" Command to Child2ViewModel, in a way that it removes itself from its parent's collection:

private void DeleteSelf()
  //First I delete the item through the model:

  //Then I need to remove it from the parent's viewmodel collection:

this.Parent.Children is the ObservableCollection<Child2ViewModel>. Since I am within the element I am deleting, when I remove it from the collection, will the garbage collector detect this and trash the object since the only reference to it was within the ObservableCollection? Or will it not kick in since i'm actuall

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend