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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:55:01+00:00 2026-05-14T18:55:01+00:00

I have a class and got a method that doin so many things in

  • 0

I have a class and got a method that doin so many things in memory and need to be disposed when its jobs done.But i have looked for MSDN for solution.There is an example thats not solved my problem.When my Class is instanced and run this method my memory is getting bigger and bigger.How can i Dispose it when its job done ?
Here is my CODES ;

class Deneme
{
    public Deneme()
    { }
    ~Deneme()
    {
        GC.Collect();
        GC.SuppressFinalize(this);
    }
    public void TestMetodu()
    {
        System.Windows.Forms.MessageBox.Show("Test");
       // This is my method that doing big jobs :)
    }



}

 Deneme CCCX = new Deneme();
        CCCX.TestMetodu();
        CCCX = null;

So i cant dispose it with this.

  • 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-14T18:55:02+00:00Added an answer on May 14, 2026 at 6:55 pm
    ~Deneme()
        {
            GC.Collect();
            GC.SuppressFinalize(this);
        }
    

    You don’t need to use GC.Collect() or GC.SuppressFinalize(this);, because at this point, the garbage collector is already collecting the object.

    You want to use the Dispose method, so you can encapsulate the object use in a using statement. Here is a link that will show you the pattern on how to implement it:

    http://www.c-sharpcorner.com/UploadFile/Ashish1/dispose02152006095441AM/dispose.aspx

    link to MSDN:

    http://msdn.microsoft.com/en-us/library/system.idisposable.dispose.aspx

                private bool IsDisposed
                {
                    get;set;
                }
    
                public void Dispose()
                {
                     Dispose(true);
                     GC.SuppressFinalize(this);
                }
    
                ~CLASS_NAME()
                {
                     Dispose(false);
                }
    
                protected virtual void Dispose(bool disposedStatus)
                {
                    if (!IsDisposed)
                    {
                         IsDisposed = true;
    
                         // Released unmanaged Resources
                         if (disposedStatus)
                         {
                          // Released managed Resources
                         }
                     }
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 375k
  • Answers 375k
  • 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 The standard image width to use for this sort of… May 14, 2026 at 8:21 pm
  • Editorial Team
    Editorial Team added an answer Since you tagged your question with jquery-validate. Here an Answer… May 14, 2026 at 8:21 pm
  • Editorial Team
    Editorial Team added an answer No, the bundle cannot be updated. Items in the bundle… May 14, 2026 at 8:21 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.