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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:54:16+00:00 2026-06-08T11:54:16+00:00

I currently have a class where I am storing a static collection that gets

  • 0

I currently have a class where I am storing a static collection that gets objects added and removed as certain methods are called. Here is the current code:

public class MatchMaker : Hub
    {

    private static HashSet<SoloUser> soloUsers = new HashSet<SoloUser>();

     //Client Requests
    public void findNewPartner(string Name, string Country)
    {

        SoloUser soloUser = soloUsers.Users.FirstOrDefault(s => (s.Name == Name) && (s.Country == Major));
        if (soloUsers.Users.Count > 0){
            Clients.partnerRequestResult(soloUsers.Users.FirstOrDefault());
            soloUsers.Users.Remove(soloUser);
            Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
            long totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
            Debug.WriteLine("TotalMemoryUsed: " + totalBytesOfMemoryUsed);
        }
        else
        {
            soloUser = new SoloUser { 
                Name = Name,
                Country = Country                       
            };
            soloUsers.Users.Add(soloUser);
            Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
            long totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
            Debug.WriteLine("TotalMemoryUsed: " + totalBytesOfMemoryUsed);
        }



    }
}

When I run:

Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
long totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
Debug.WriteLine("TotalMemoryUsed: " + totalBytesOfMemoryUsed);

an object is added or removed from the collection the output of totalBytesOfMemoryUsed gets larger and larger(by 2mb each time) whether or not i add or remove the object from the collection, is this due to a memory leak? Is this even a sufficient way to check memory management? Do i need to dispose an object when i remove it from the collection?

  • 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-06-08T11:54:17+00:00Added an answer on June 8, 2026 at 11:54 am

    It is a good practice to dispose of any objects that implement IDisposable as soon as you are finished with them.

    Given that, you need to remember that the .NET Garbage Collector is non-deterministic. This means you aren’t going to necessarily know beforehand when a collection is going to occur. When the run-time needs to perform a collection, it will try and do that. You shouldn’t be afraid of 2mb anyways. Let the Garbage Collector do it’s job.

    Trying to analyze your program’s memory usage by getting the working set of memory or looking at the Windows Task Manager is usually a trip down the rabbit hole. Use a memory profiler after you actually have a problem (such as ANTS).

    I also suggest reading MSDN regarding the Garbage Collector in general. You can start here.

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

Sidebar

Related Questions

I currently have a class called clientActivity that contains a finger paintig activity that
I currently have a helper class that I am using to obfuscate a static
We currently have a utilities class that handles a lot of string formatting, date
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently I have a class that is extending the ListActivity class. I need to
I currently have service classes that look something like this public class UserService :
I have a class with a collection of Wildcard Types that is a singleton,
I currently have a class file with the following enumeration: using System; namespace Helper
I currently have a class where I need accomplish the equivalent of the following
I am developing a web form using Visual Web Developer Currently I have class

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.