Solved

Free up memory used by a dataset

Posted on 2004-08-18
5
346 Views
Last Modified: 2010-04-15
The code:
DataSet ds = new DataSet();
OleDbAdapter da = new OleDbAdapter(sqltext, connection);
da.Fil(ds, "foo");
the command text is a select command retrieving lots of data. After that call the memory jumps up (by more than 100M).
Then I try to clean up the dataset by:
ds.Tables["foo"].Clear();
ds.Dispose();
ds = null;
But the memory decreases by only a fraction of the above (about 10-20M).
What's wrong with the code, how can I free up the memory used by the dataset.
Thannks.
0
Comment
Question by:phunv
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
s_sansanwal earned 125 total points
ID: 11837506
Refer
http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21054094.html

Also, Dispose would put the DataSet in Garbage Collector queue and would not force GC.

Read

Forcing a Garbage CollectionSee Also
Programming for Garbage Collection | GC Class
The garbage collection GC class provides the GC.Collect method, which you can use to give your application some direct control over the garbage collector. In general, you should avoid calling any of the collect methods and allow the garbage collector to run independently. In most cases, the garbage collector is better at determining the best time to perform a collection. In certain rare situations, however, forcing a collection might improve your application's performance. It might be appropriate to use the GC.Collect method in a situation where there is a significant reduction in the amount of memory being used at a defined point in your application's code. For example, an application might use a document that references a significant number of unmanaged resources. When your application closes the document, you know definitively that the resources the document has been using are no longer needed. For performance reasons, it makes sense to release them all at once. For more information, see the GC.Collect Method.

Before the garbage collector performs a collection, it suspends all currently executing threads. This can become a performance issue if you call GC.Collect more often than is necessary. You should also be careful not to place code that calls GC.Collect at a point in your program where users could call it frequently. This would defeat the optimizing engine in the garbage collector, which determines the best time to run a garbage collection.

Reference: MSDN

Cheers,
S Sansanwal
0
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 11837509
0
 
LVL 8

Expert Comment

by:vinhnl
ID: 11837594
DataSet ds = new DataSet();
OleDbAdapter da = new OleDbAdapter(sqltext, connection);
da.Fil(ds, "foo");
the command text is a select command retrieving lots of data. After that call the memory jumps up (by more than 100M).
Then I try to clean up the dataset by:
ds.Tables["foo"].Clear();
ds.Dispose();
ds = null;
GC.Collect();

Good Luck,
VINHNL
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now