473,466 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using GC.Collect() in a timer

Hello,

I am wondering if it is a good idea to use GC.Collect() in a timer. For
example, timer is fired every 5 minutes and calls GC.Collect().

In our server app the memory goes to 600MB and stays there. The memory
hardly goes down. When I disconnect the client and the connect it again the
memory could reclaim to 400MB. But it could go down to 50 MB.
The reason that the memory goes that much high is that has to fill the
dataset with huge data.

thanks,

Mike
Oct 27 '07 #1
9 3100
In article
<3B**********************************@microsoft.co m>Mike9900
<Mi******@discussions.microsoft.comwrote:
Hello,
I am wondering if it is a good idea to use GC.Collect() in a timer.
For example, timer is fired every 5 minutes and calls GC.Collect().
It's not even a good idea to use GC.Collect() without a timer.
In our server app the memory goes to 600MB and stays there. The
memory hardly goes down. When I disconnect the client and the connect
it again the memory could reclaim to 400MB. But it could go down to
50 MB.
But does it need to? Even assuming you're monitoring memory usage
correctly, the fact that there appears to be such a large amount of
memory being held is not necessarily a problem. Assuming that if and
when you actually need to _use_ that memory, you get it as necessary,
there's nothing to worry about.

Pete

--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 27 '07 #2
There are some very specific instances where it is a good idea to make a
manual call to Collect, but in a server environment, it's rare (because
those instacnes are when you have a non-recurring or rarely occuring event,
which is unlikely in a server environment). See Rico Mariani's blog entry
on the matter for more information:

http://blogs.msdn.com/ricom/archive/...29/271829.aspx

Specifically, Rule #2. I do agree that generally, Rule #1 is pretty
much always the standard, and I personally haven't found a reason to use
GC.Collect in code I've written yet.

I definitely don't see anything in the post here that says that Rule #2
should be applied here.

I also completely agree with the statement about it not mattering if
your memory consumption is high on the server. Referring the blog entry
above, you want the server to get into that sweet spot where the GC is tuned
correctly to the behavior of your app, and constantly shifting memory
consumption isn't going to help that.

If I had to guess (and I could be wrong) as well, I agree with you that
the OP is probably looking at the working set in Task Manager, and not the
actual performance counters. And as we all know, the working set in Task
Manager <memory consumption.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:ne*****************@news1.iinet.com...
In article
<3B**********************************@microsoft.co m>Mike9900
<Mi******@discussions.microsoft.comwrote:
> Hello,
> I am wondering if it is a good idea to use GC.Collect() in a timer.
For example, timer is fired every 5 minutes and calls GC.Collect().

It's not even a good idea to use GC.Collect() without a timer.
> In our server app the memory goes to 600MB and stays there. The
memory hardly goes down. When I disconnect the client and the connect
it again the memory could reclaim to 400MB. But it could go down to
50 MB.

But does it need to? Even assuming you're monitoring memory usage
correctly, the fact that there appears to be such a large amount of
memory being held is not necessarily a problem. Assuming that if and
when you actually need to _use_ that memory, you get it as necessary,
there's nothing to worry about.

Pete

--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Oct 27 '07 #3
Mike9900 wrote:
I am wondering if it is a good idea to use GC.Collect() in a timer. For
example, timer is fired every 5 minutes and calls GC.Collect().

In our server app the memory goes to 600MB and stays there. The memory
hardly goes down. When I disconnect the client and the connect it again the
memory could reclaim to 400MB. But it could go down to 50 MB.

The reason that the memory goes that much high is that has to fill the
dataset with huge data.
Generally extra GC's will:
- decrease overall throughput
- reduce differences in throughput over time

But once every 5 minutes sounds as a complete waste of time.

Arne
Oct 27 '07 #4
What if we call GC.Collect() once every 30 minutes?

I have found that it reduces the memory from 500MB to 200MB in the task
manager.
--
Mike
"Arne Vajhøj" wrote:
Mike9900 wrote:
I am wondering if it is a good idea to use GC.Collect() in a timer. For
example, timer is fired every 5 minutes and calls GC.Collect().

In our server app the memory goes to 600MB and stays there. The memory
hardly goes down. When I disconnect the client and the connect it again the
memory could reclaim to 400MB. But it could go down to 50 MB.

The reason that the memory goes that much high is that has to fill the
dataset with huge data.

Generally extra GC's will:
- decrease overall throughput
- reduce differences in throughput over time

But once every 5 minutes sounds as a complete waste of time.

Arne
Oct 27 '07 #5
In article
<F2**********************************@microsoft.co m>Mike9900
<Mi******@discussions.microsoft.comwrote:
What if we call GC.Collect() once every 30 minutes?
I have found that it reduces the memory from 500MB to 200MB in the
task manager.
But why do you care what the memory usage shown in Task Manager is?

Unless there is some demonstrable performance issue that you're trying
to solve, you should not be messing with GC.Collect(). It's a waste
of time and can actually interfere with the normal, reliable,
efficient operation of the garbage collector.

Just let the garbage collector decide when and how to manage the
memory. That's its job, and in the vast majority of situations it
knows how to do that job much better than you or I do.

Pete

--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 27 '07 #6
Yes, I do not need to care. Iwas just wondering.

But, what about the UI? The ListView is loaded with millions of items and
the memory goes to more than 1GB, but when I close the form, it is not
reclaimed. So, is GC a good idea in a timer in the UI client?
--
Mike
"Peter Duniho" wrote:
In article
<F2**********************************@microsoft.co m>Mike9900
<Mi******@discussions.microsoft.comwrote:
What if we call GC.Collect() once every 30 minutes?
I have found that it reduces the memory from 500MB to 200MB in the
task manager.

But why do you care what the memory usage shown in Task Manager is?

Unless there is some demonstrable performance issue that you're trying
to solve, you should not be messing with GC.Collect(). It's a waste
of time and can actually interfere with the normal, reliable,
efficient operation of the garbage collector.

Just let the garbage collector decide when and how to manage the
memory. That's its job, and in the vast majority of situations it
knows how to do that job much better than you or I do.

Pete
--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 27 '07 #7
In article
<C9**********************************@microsoft.co m>Mike9900
<Mi******@discussions.microsoft.comwrote:
Yes, I do not need to care. Iwas just wondering.
But, what about the UI? The ListView is loaded with millions of
items and the memory goes to more than 1GB, but when I close the
form, it is not reclaimed.
Define "reclaimed". Are you seeing some genuine performance problem?

If not, then don't worry. If you are, then there's almost certainly a
better way to deal with it than calling GC.Collect().
So, is GC a good idea in a timer in the UI
client?
No.

Pete

--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 28 '07 #8
Mike,

With all due respect, one million items is a ridiculous amount of items
to have in the ListView. I strongly suggest finding a different way of
presenting the information to the user, as being able to process one million
items at once is a challenge for anyone.

Additionally, if you must use that many items in the ListView, are you
at least virtualizing it, instead of creating one million ListViewItems?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mike9900" <Mi******@discussions.microsoft.comwrote in message
news:C9**********************************@microsof t.com...
Yes, I do not need to care. Iwas just wondering.

But, what about the UI? The ListView is loaded with millions of items and
the memory goes to more than 1GB, but when I close the form, it is not
reclaimed. So, is GC a good idea in a timer in the UI client?
--
Mike
"Peter Duniho" wrote:
>In article
<F2**********************************@microsoft.c om>Mike9900
<Mi******@discussions.microsoft.comwrote:
What if we call GC.Collect() once every 30 minutes?
I have found that it reduces the memory from 500MB to 200MB in the
task manager.

But why do you care what the memory usage shown in Task Manager is?

Unless there is some demonstrable performance issue that you're trying
to solve, you should not be messing with GC.Collect(). It's a waste
of time and can actually interfere with the normal, reliable,
efficient operation of the garbage collector.

Just let the garbage collector decide when and how to manage the
memory. That's its job, and in the vast majority of situations it
knows how to do that job much better than you or I do.

Pete
>--
>I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo

Oct 28 '07 #9
On Oct 27, 5:53 pm, Mike9900 <Mike9...@discussions.microsoft.com>
wrote:
Yes, I do not need to care. Iwas just wondering.

But, what about the UI? The ListView is loaded with millions of items and
the memory goes to more than 1GB, but when I close the form, it is not
reclaimed. So, is GC a good idea in a timer in the UI client?
--
I don't know what your UI is presenting, but IMO, if you have a
million (or more) items in a ListView, you have a flawed design. A
user could spend hours trying wade through a million items in a
listview.

Chris

Oct 29 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Qiangning Hong | last post by:
A class Collector, it spawns several threads to read from serial port. Collector.get_data() will get all the data they have read since last call. Who can tell me whether my implementation correct?...
1
by: Jason | last post by:
I've got a standard form on an ASP page to collect resumes from visitors. The page can be accessed only after the visitor has logged into the site. The issue that I'm running into is that the users...
3
by: ray | last post by:
Hi, I just wrote a windows service application to call a function of another object periodically. I used System.Server.Timer and I found that it works fine within the first 2 hours but the...
14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
6
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically,...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
4
by: archana | last post by:
Hi all, I want to develop one windows service in which i want to provide some scheduling facility. What i want is to take start time frm one xml file and then at that specified start time. ...
6
by: semkaa | last post by:
Can you explain why using ref keyword for passing parameters works slower that passing parameters by values itself. I wrote 2 examples to test it: //using ref static void Main(string args) {...
2
by: Amit Dedhia | last post by:
Hi I am developing a scientific application which has moderate level image processing involved. In my application, there is a main application form which invokes another form. When this form...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.