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

  • Home
  • SEARCH
  • 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 3283282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:01:22+00:00 2026-05-17T20:01:22+00:00

I’m using the .NET4 WPF DataGrid to show a SQL table containing lots of

  • 0

I’m using the .NET4 WPF DataGrid to show a SQL table containing lots of images.

The XAML code in question is:

...
<DataGridTemplateColumn.CellTemplate>
   <DataTemplate>
      <Image Source="{Binding Converter={StaticResource ImageConverter}, Path=Picture}" Stretch="Uniform" MaxHeight="200" />
   </DataTemplate>
</DataGridTemplateColumn.CellTemplate>
...

And the ImageConverter is written as such:

[ValueConversion(typeof(Binary), typeof(BitmapImage))]
public class ImageConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value != null)
        {
            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            bi.StreamSource = new System.IO.MemoryStream((value as Binary).ToArray());
            bi.EndInit();
            if (bi.CanFreeze) bi.Freeze();

            return bi;
        }
        else return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

My question is does the code above leak memory?

I have tried to do some profiling about this, but I’m not sure if I’m interpreting the results correctly.

First of all, the SQL table containing the images uses 38MB of disk space (the images should be stored in png format). After loading all the images to the datagrid via LINQ, the app uses some 170+ MB extra RAM. This can probably be contributed to uncompressing the images and the fact that the wpf datagrid is a gigantic memory hog even when virtualizing is enabled. After closing the window the memory usage does not drop. Reopening the window causes another 170+ MB of RAM to be used, making the total memory usage roughly 400MB. If I reopen the window again, then the memory usage drops to about 330MB. Reopening the window again takes the memory usage to 380MB. Reopening again takes it to 270MB. Reopening again takes it to 426MB. So as you can see very fluctuating…

This little bit of testing was done with Win7 x64 and 8GB of RAM (the app is compiled with the Any CPU option).

I did try the same test on a virtual xp machine with <512MB of ram (about 384 if I remember correctly). And everytime I reopened the window I first saw a dramatic drop in memory usage when the window was being loaded and then the same amout of memory reused, so the overall usage was about the same.

I interpret those results such that the GC doesn’t bother cleaning up unless there is high pressure on the memory subsystem. But in that case calling GC.Collect() after I close the window should release the majority of the memory? Only that I didn’t, I saw only a drop of a 4-6MB in memory usage when I called GC.Collect (I also tried all the possible parameters, including forcing collection on all generations and calling GC.WaitForPendingFinalizers()).

This got me thinking that maybe the unused leaking data is being pushed into the page file. But the page file usage drops and rises acording to the memory usage equaly.

All things considered there ought not to be a memory leak here, but I can’t get the memory usage to come down after I have closed the window. I did try to attach some .NET profiler to my process, but thoses profilers are so complex that I can’t quite figure out whether the shown image objects are still alive and referenced by something. Or are they dead and the GC simply hasn’t cleaned them up…

  • 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. Editorial Team
    Editorial Team
    2026-05-17T20:01:22+00:00Added an answer on May 17, 2026 at 8:01 pm

    The way you can find out whether or not the memory is written to the page file is through GC.GetTotalMemory(true). This should return the actual memory consumption of the .NET process including any pages that may have been written to the page file.

    This may even be different from e.g. the memory reported by the task manager, but it will report what has actually been allocated by .NET objects.

    See http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/2ebbff38-f881-47ad-a4b4-9c9157fb3b5b for more information concerning the difference in memory consumption reported by the task manager and GetTotalMemory.

    My guess is that GC.GetTotalMemory(true) will report that all memory has actually been released after the collection.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
I want to count how many characters a certain string has in PHP, but
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.