I have a WPF application that stops after running out of memory ...
These are basically TreeView display nodes, which are instances of the Linq To Sql OR Generated class ICTemplates.Segment. There are about 20 tables indirectly linked through associations with this class in the OR designer.
<TreeView Grid.Column="0" x:Name="tvwSegments" ItemsSource="{Binding}" SelectedItemChanged="OnNewSegmentSelected"/> <HierarchicalDataTemplate DataType="{x:Type local:Segment}" ItemsSource="{Binding Path=Children}"> ... // code behind, set the data context based on user-input (Site, Id) KeeperOfControls.DataContext = from segment in tblSegments where segment.site == iTemplateSite && segment.id == iTemplateSid select segment;
I added an explicit Child property to the segment class that is looking for another table with parent records.
public IEnumerable<Segment> Children { get { System1ConfigDataContext dc = new System1ConfigDataContext(); return from link in this.ChildLinks join segment in dc.Segments on new { Site = link.ChildSite, ID = link.ChildSID } equals new { Site = segment.site, ID = segment.id } select segment; } }
The rest is data binding in combination with data templates to display each segment as a set of user interface controls.
I am sure that children load on demand (when I expand the parent) based on the response time. When I expand a node with children of 70 , it takes some time before the children are loaded (task manager shows using Mem as 1000000K!). If I parse the next node with approximately 50 children, BOOM! OutOfMemoryException
I ran VS Profiler to dig deeper and here are the results
Dashboard Objects of Life Distribution
The top 3 are Action, DeferredSourceFactory.DeferredSource, and EntitySet (all .Net / LINQ classes). The only user classes are segment [] and the segment is included in # 9 and # 10.
I canโt think of the persecution. What could be the reason?
profiling linq-to-sql wpf treeview
Gishu
source share