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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:55:13+00:00 2026-06-12T21:55:13+00:00

I am developing a utility class that contains static methods that will be frequently

  • 0

I am developing a utility class that contains static methods that will be frequently called by multiple threads. I am noticing that memory use is growing over time, so it seems to me that I have some memory leaks.

Here is a simple example of the pattern I am using for these static methods:

public static int CreateNewThing(int IDofSomeDBObjectHoldingInfoToCreateNewThing)
{
    using(SomeDBContext context = new SomeDBContext(connectionString))
    {
        SomeDBObjectHoldingInfoToCreateNewThing createNewThingyInfo = context.SomeDBObjectsHoldingInfoToCreateNewThing.First(obj => obj.ID == IDofSomeDBObjectHoldingInfoToCreateNewThing);
        // Do some stuff to create the new object
        // Return the ID of the newly created thingy...
        return theNewThingThatWasCreated.ID;
     }
}

My question is whether using ‘using’ statements or directly calling Dispose inside static methods actually clears up any memory. Granted, I haven’t stated the overall architecture or purpose of this application, but I am also wondering if I’m using the best pattern here. What are the best practices for creating thread-safe utility classes in .NET?

  • 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-12T21:55:15+00:00Added an answer on June 12, 2026 at 9:55 pm

    I am noticing that memory use is growing over time, so it seems to me that I have some memory leaks.

    Not necessarily – you’d need to give more data for us to really have a good idea about that.

    My question is whether using ‘using’ statements or directly calling Dispose inside static methods actually clears up any memory.

    using statements aren’t about cleaning up memory. That’s the GC’s job. They’re about releasing non-memory resources. Whether you’re in a static method or not is completely irrelevant to whether the SomeDBContext ought to be disposed or not.

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

Sidebar

Related Questions

I'm developing a C# utility class that runs an external command on a Linux
I'm a bit stumped here. I am developing a feedback utility that will allow
I am developing a little utility view that will be embedded in several of
I'm developing a utility class to handle Actions from Java Swing components; I would
I have been developing a small Java utility that uses two frameworks: Encog and
I'm developing a jar library for utility use. I want to significantly reduce the
I'm developing a small utility app that scans 2D barcodes, and then submits each
I'm developing a REST API, and am looking for a simple graphic utility that
I am currently developing a utility class as a part of my business layer.
I'm developing a small utility application that needs to detect whether another one has

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.