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 4029076
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:17:59+00:00 2026-05-20T11:17:59+00:00

I’ve got a class that stores an image along with it’s filename. I’ve created

  • 0

I’ve got a class that stores an image along with it’s filename. I’ve created an ObservableCollection of this class, and bound that to a WPF listbox. (It’s an image viewer of sorts)

I load 50 meg worth of data (currently about 10 images), then I want to remove one, some or all of the images from the observable collection and replace them (so that the memory footprint doesn’t get too big while scrolling through many images).

For a start, I’ve actually got a button on the GUI to load the “next 10 images” – which it does, but it doubles the memory footprint. I’ve tried calling .Clear() and .ClearItems() from the collection, and also .Remove() and .RemoveAt(n) but the memory doesn’t decrease. Am I mistunderstanding how ObservableCollection works?

Here’s a synopsis of my code:

public class ImageDataList : ObservableCollection
            {

public static ImageDataList Load(string path,int startVal, ImageDataList images) { // Load 10 images from defined start position if (startVal<0) startVal=0; int endVal = startVal + 10; if (endVal > Directory.GetFiles(path).Length) endVal = Directory.GetFiles(path).Length; // Attempt to clear all data from collection images.ClearItems(); images.Clear(); while (images.Count>1) { images.RemoveAt(0); } for (int i = startVal; i < endVal; i++) { string filename = Directory.GetFiles(path)[i]; if (filename.Contains(".tif")) { ImageData imgData = ImageData.Load(filename); images.Add(imgData); } } return images; } }

After loading the images, it’s passed to the GUI via:

listBox.DataContext = images;

I hope I’ve been clear… let me know if I should add anything!

Edit: For now I seem to have solved the problem by overwriting an item in the ObservableCollection, rather than trying to remove/clear it then add a new one. I still don’t understand the memory problem though.

  • 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-20T11:18:00+00:00Added an answer on May 20, 2026 at 11:18 am

    It may be that the garbage collector hasn’t deleted the image objects from memory yet. The reason may be that you have enough memory available on your system so there is no need to delete the objects yet.

    Does the memory consumption continue to rise when you load the next 10 images and the next 10 after that?

    You should also consider disposing the images as Rakesh Gunijan suggests.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.