Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 98241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:09:30+00:00 2026-05-11T00:09:30+00:00

I have a WPF App which is grinding to a halt after running out

  • 0

I have a WPF App which is grinding to a halt after running out of memory…
It is basically a TreeView displaying nodes, which are instances of Linq To Sql OR Generated class ICTemplates.Segment. There around 20 tables indirectly linked via associations to 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’ve added an explicit property called Children to the segment class which looks up another table with parent-child 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 of it is data binding coupled with data templates to display each Segment as a set of UI Controls.

I’m pretty certain that the children are being loaded on-demand (when I expand the parent) going by the response time. When I expand a node with around 70 children, it takes a while before the children are loaded (Task manager shows Mem Usage as 1000000K!). If I expand the next node with around 50 children, BOOM! OutOfMemoryException

I ran the VS Profiler to dig deeper and here are the results

Summary Page Object Lifetimes Allocation

The top 3 are Action, DeferredSourceFactory.DeferredSource and EntitySet (all .Net/LINQ classes). The only user-classes are Segment[] and Segment come in at #9 an #10.

I can’t think of a lead to pursue.. What could be the reason ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:09:31+00:00Added an answer on May 11, 2026 at 12:09 am

    The issue seems to be the creation of multiple S1DataContext objects as Sirocco referred to. I tried the using statement to force a Dispose and make it eligible for collection. However it resulted in an ObjectDisposedException that I can’t make sense of.

    1. The control goes from the line that sets the data context of the DockPanel KeeperOfAllControls.
    2. [External Code] (shown in call stack)
    3. Segment.Children.get (has a using block with dc)
    4. Back at the Line in Step 1… ObjectDisposedException the Linq query uses tblSegments which is retrieved from a local instance of S1DataContext

    Anyways so i assume that there is something that prevents multiple DataContexts from being created and disposed. So I tried a Singleton DataContext.
    And it works!

    • the TreeView control is significantly more responsive, every node I tried loads in 3-4 secs max.
    • I put in a GC.Collect (for verification) before every fetch/search and now the memory usage stays between 200,000-300,000K.

    The OR generated System.Data.Linq.DataContext doesn’t seem to go away unless it is disposed explicitly (eating memory). Trying to Dispose it in my case, didn’t pan out.. even though both functions had their own using blocks (no shared instance of DataContext). Though I dislike Singletons, I’m making a small internal tool for devs and hence don’t mind it as of now.. None of the LinqToSql samples I saw online.. had Dispose calls mandated.

    So I guess the problem has been fixed. Thanks to all the people that acted as more eyeballs to make this bug shallow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a client VB .NET 3.5 WPF app which is basically a test
I have a WPF app in which I need to programatically manipulate at runtime.
I'm developing a WPF app in which I have a ScrollViewer with grid (16
I am new to WPF and .net. I have a WPF app which someone
I have a WPF 4 app which I want to enable drag and drop
I have a simple wpf app which has a button that increments a value
I have successfully created a asp mvc app which basically has interface, service and
I have a C# WPF GUI app (C#App1) which among other things, reads lines
In WPF app I have a ListView which is connected with ObservableCollection ShQuCollection through
In WPF app I have a WCF service which dynamically fills a generic List

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.