By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

Releasing memory from a DataTable

P: n/a
I have a service that is pulling alot of records from a SQL Server table in a DataSet. This process takes up alot of memory, which is to be expected. But when the process is finished, I am clearing all the data I thought with:

MyDataSet.Tables("MyTable1").Rows.Clear()
MyDataSet.Tables("MyTable2").Rows.Clear()
MyDataSet.Tables("MyTable3").Rows.Clear()

But I'm monitoring the memory the process is doing and this isn't freeing the memory. Is there something I need to do to flush the memory?
Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
GC.Collect()

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Sean" <Se**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
I have a service that is pulling alot of records from a SQL Server table in a DataSet. This process takes up alot of memory, which is to be expected.
But when the process is finished, I am clearing all the data I thought with:
MyDataSet.Tables("MyTable1").Rows.Clear()
MyDataSet.Tables("MyTable2").Rows.Clear()
MyDataSet.Tables("MyTable3").Rows.Clear()

But I'm monitoring the memory the process is doing and this isn't freeing

the memory. Is there something I need to do to flush the memory?
Nov 20 '05 #2

P: n/a
Hi Sean,

Releasing memory is a managed process it is done when it is needed. Are you
sure it is absolutly needed when you see it not set free. (I mean does your
program hangs after that?)

Cor
Nov 20 '05 #3

P: n/a
Sean,

You should not have to do that normally, as I tried to tell, the framework
should do that, however do not expect that it happens direct. That is one of
the reasons that it is called managed code.

Are you sure your program becomes slower and it it is not the normal loading
of the dataset again.

Why are you not using dataset.clear by the way?

http://msdn.microsoft.com/library/de...cleartopic.asp

Cor
No, it doesn't hang...it works but when I look at process in task manager, the memory isn't released, and I can see the machine start to get bogged
down. Let me step back....when I start the service, it's running at about
17kb memory. When I get to my data adapter fill statement (as it loads my
dataset), I watch the memory increase to about 400,000kb for that one
statement as my records are loaded for the process. When I am done using the
data, I clear the DataTable that I filled, but that 380,000kb of memory
isn't freed (the memory usage actually increases a little bit when I clear).
I tried doing a GC.Collect() but that didn't help. I'm trying to figure out
how I flush that memory now that I am not using it anymore. Thanks alot for
any help.
Sean

"Cor Ligthert" wrote:
Hi Sean,

Releasing memory is a managed process it is done when it is needed. Are you sure it is absolutly needed when you see it not set free. (I mean does your program hangs after that?)

Cor

Nov 20 '05 #4

P: n/a
Sean,
How are you "monitoring the memory the process is doing"?

CLR Profiler is a tool you can reliably use to see if you app is not
releasing memory as it should.

Info on the CLR Profiler:
http://msdn.microsoft.com/library/de...nethowto13.asp

http://msdn.microsoft.com/library/de...anagedapps.asp

In addition to the above articles, The following articles provide
information on writing .NET code that performs well. I believe one of the
covers how to use Performance Monitor under Control Panel to monitor the
memory usage of your app.

http://msdn.microsoft.com/architectu...l/scalenet.asp

http://msdn.microsoft.com/library/de...anagedcode.asp

http://msdn.microsoft.com/library/de...anagedapps.asp

http://msdn.microsoft.com/library/de...vbnstrcatn.asp

http://msdn.microsoft.com/library/de...tchperfopt.asp

http://msdn.microsoft.com/library/de...tperftechs.asp

Hope this helps
Jay


"Sean" <Se**@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
I have a service that is pulling alot of records from a SQL Server table in a DataSet. This process takes up alot of memory, which is to be expected.
But when the process is finished, I am clearing all the data I thought with:
MyDataSet.Tables("MyTable1").Rows.Clear()
MyDataSet.Tables("MyTable2").Rows.Clear()
MyDataSet.Tables("MyTable3").Rows.Clear()

But I'm monitoring the memory the process is doing and this isn't freeing

the memory. Is there something I need to do to flush the memory?
Nov 20 '05 #5

P: n/a
Hi Sean,

There is as well a
dataset.tables(0).clear

http://msdn.microsoft.com/library/de...ClearTopic.asp

Setting to nothing *should* not do anything in your problem

I hope this helps

Cor
Nov 20 '05 #6

P: n/a
> > dataset.tables(0).clear...
How is that different from referencing the table by name instead of index?


That is the same I did not look at your original message, it is more a
shortcut to tell it is a datatable, however you are now clearing the row
collection.

(Not that I know if that will make any difference)

Cor
Nov 20 '05 #7

P: n/a
Sean,
In addition to the other articles I mentioned, it sounds like you may really
want to start here:

Every thing you wanted to know about the GC but were afraid to ask:

http://msdn.microsoft.com/msdnmag/issues/1100/gci/
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/

As it sounds like you are looking at the amount of OS memory allocated,
thinking that managed memory is allocated. The GC (.NET Garbage Collector)
will actually allocate as much OS memory as it can, then allocates managed
objects (such as DataTable) from this memory. If the OS doesn't say it wants
the memory back, the GC will hang on to the OS memory until it needs it
again.

The "bogged down" feeling, may actually be due to the performance of your
app (the other articles I mentioned) and not this perceived memory abuse.

Hope this helps
Jay

"Sean" <Se**@discussions.microsoft.com> wrote in message
news:62**********************************@microsof t.com...
Oh I see. Yeah, I had actually changed it already in an attempt to see if that released the memory better (it didn't). Huh, thanks for the input. this
stuff is just driving me crazy. Every keeps telling me that it is working
correctly, but I guess I'm not seeing it considering it is holding on to
almost 600MB out of 1GB of memory after I'm done with it. It seems to
release it (or reuse) it on the next iteration, but everything is bogged
down a little bit by it hanging on to so much memory. Thanks.
Sean

Nov 20 '05 #8

P: n/a
Sean,

Can you do a trick for me. Just to try.
Can you set after the tables clear this statements
\\\
GC.Collect()
me.show
///

I am curious what it does.

Cor
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.