Solved

Free up memory used by a dataset

Posted on 2004-08-18
5
351 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

724 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