Solved

Free up memory used by a dataset

Posted on 2004-08-18
5
350 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Suggested Courses

737 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