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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:18:57+00:00 2026-05-13T23:18:57+00:00

I am trying to improve performance by limiting my objects in memory by using

  • 0

I am trying to improve performance by limiting my objects in memory by using a cache.

This creates problem with my ObservableCollection. Well, i think the code speaks for itself. I have “transformed” my ObservableCollection-derivative to this:

public class TrackCollection : INotifyPropertyChanged, IEnumerable {
    private readonly List<Guid> _guids = new List<Guid>();

    public event PropertyChangedEventHandler PropertyChanged;

    private void NotifyPropertyChanged(String info) {
        if (PropertyChanged != null) {
            PropertyChanged(this, new PropertyChangedEventArgs(info));
        }
    }

    public void Add(Track track) {
        _guids.Add(track.Id);
    }

    public void Add(Guid trackId) {
        _guids.Add(trackId);
    }

    public IEnumerator GetEnumerator() {
        var tracks = new List<Track>(_guids.Count);
        foreach(Guid id in _guids)
            tracks.Add(MediaCache.Instance.GetTrack(id));

        return tracks.GetEnumerator();
    }
}

When i call the Add-methods i would like to call my NotifyPropertyChanged on the class it self.

I have a feeling that this is the wrong approach to this kind of problem, it feels like a workaround.

Anyways, is this the correct solution, and if so, how should i proceed?


The cache method looks like this:

    private readonly List<Track> _tracks = new List<Track>();
    public Track GetTrack(Guid id) {
        foreach (var track in _tracks.Where(track => track.Id == id))
            return track;

        _tracks.Add(Database.Database.Instance.GetTrack(id));
        return _tracks[_tracks.Count - 1];
    }
  • 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-13T23:18:57+00:00Added an answer on May 13, 2026 at 11:18 pm

    If you want your collection to be observable by the binding system, you need to implement INotifyCollectionChanged. This will allow you to notify interested clients about changes in your collection.

    On a side note, to notify listeners about a change in the whole class, you can notify about a change to a property with null passed for the name. This will cause all bindings to reevaluate the source.


    I looked through the code a bit further and I’m confused about your intention. Every enumeration returns a brand new collection, which doesn’t mesh well with the notion of an observable collection. The clients of an observable collection expect the individual instances of their items to stay consistent, so they only need to respond to restructuring, rather than refreshing the whole list. Could your clarify what you’re trying to accomplish?


    Instead of trying to handle your caching in the collection class, perhaps you can create a ‘reference’ class TrackReference and use a standard ObservableCollection. The class would look something like:

    public class TrackReference
    {
        private Guid _id;
    
        public Track Track
        {
            get { return MediaCache.Instance.GetTrack(id); }
        }
    
        public TrackReference(Track track)
        {
            _id = track.Id;
        }
    
        public TrackReference(Guid trackId)
        {
            _id = trackId;
        }
    }
    

    Now you have a lightweight handle you can pass around (and observe in a collection) that gives you access to the full Track data when you’re ready for it. This is also a good place to add any lightweight meta-data (track name, perhaps?) for your UI classes to Bind.

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

Sidebar

Ask A Question

Stats

  • Questions 367k
  • Answers 367k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer awk '{array[$1]+=$2} END { for (i in array) {print "Sum… May 14, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer By modifying the example here by removing operations I have… May 14, 2026 at 4:57 pm
  • Editorial Team
    Editorial Team added an answer No need to rebuild: the "quirks mode" actually is based… May 14, 2026 at 4:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.