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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:03:44+00:00 2026-05-26T11:03:44+00:00

My application is working 24X7 and I use DataTable for data handling. I need

  • 0

My application is working 24X7 and I use DataTable for data handling.

I need to dispose the DataTable everytime. I used Dispose and Clear methods, but the content is only cleared and its instance is still in the memory when I debugged the code.

How can I remove it from memory without depending upon the GC?

Thanks in advance..

EDIT:
This is my code prototype . i have done it in two ways.

 1     //Methord 1
 2               while (true)
 3               {
 4                   DataTable dt = new DataTable();
 5                   dt.Columns.Add("City", typeof(string));
 6                   dt.Rows.Add("ABC");
 7                   dt.Rows.Add("XYZ");
 8                   dt.Rows.Add("PQR");
 9                   dt.Rows.Add("LMN");
 10                   dt.Dispose();
 11               }
 12    //Methord 2
 13               while (true)
 14               {
 15                   using (DataTable dtable = new DataTable())
 16                   {
 17                       dtable.Columns.Add("City", typeof(string));
 18                       dtable.Rows.Add("ABC");
 19                       dtable.Rows.Add("XYZ");
 20                       dtable.Rows.Add("PQR");
 21                       dtable.Rows.Add("LMN");
 22                   }
 23               }

how will the datatable gets disposed ? if you check with breakpoint , you can stil see datatable ‘dt’ still has values even after calling dispose().even on execution of Line No 11 values are still there.i need to free that memory before execution of line 12 (or before 2nd iteration of while). what should i do here?

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

    If you set every reference to the datatable to nothing/null the underlying data can be garbage collected. When an object is orphaned the dotnet framework will automatically garbage collect when it feels it is appropriate.

    You can tell the garbage collector to collect manually, but it will only collect against objects that don’t have a reference in code.
    http://msdn.microsoft.com/en-us/library/xe0c2357.aspx

    Summary on how dotnet GC works.
    http://dotnetfacts.blogspot.com/2008/05/how-garbage-collector-works-part-1.html

    If the Garbage collector isn’t freeing up the memory, it probably because other objects,Ui Controls/Other business objects you might have written have references to row data in your datatable. For example you are displaying row data, or you have pass a row into another object and it has a reference to this row.

    If your experiencing ever increasing memory, you have a memory leak, i.e. you have an ever increasing number of objects that have references to them and the framework cant garbage collect this data because it thinks it is being used. You will need to look at your code and try and figure out why it is leaking, a memory profiler may help.

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

Sidebar

Related Questions

i have used progress bar in my application..my application is working fine but the
I need to use linq in C# Windows form application working with .Net Framework
I got my application working Awhile back, but after completely and accidentally deleting it,
As my application working fine in Portrait mode but if i change it to
On a Facebook application (working under appengine) I need to tell the user which
My application was working perfectly on localhost. But when i uploaded the application on
I have a Guice enabled application working fine, but when I optimize it (i.e.,
I have a C# app application working to some extent. What i need to
I have my application working fully on my development machine and storing data all
I have application working with SQLite DB(table with two rows) I need to recieve

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.