Memory usage problem
-
I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...
-
I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...
As far as i know, when you do something like
GC.Collect();
your not telling the garbage collector to collect the object, your merely flagging that object for garbage collection. So when the garbage collector comes along(at a later point in time) it will collect the object you flagged. If you post your code(specifically the loop) we might be able to get the memory usage down a bit...Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111 -
I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...
I believe it's not actual memory usage that you're seeing in Task Manager - just memory that Windows has pre-allocated to your app. Any memory allocated but unused will be reclaimed if needed elsewhere or when minimized which is why you're seeing those figures.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Expect everything to be hard and then enjoy the things that come easy. (code-frog) -
I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...
You may want to try GC.WaitForPendingFinalizers() as well. It's a perfomance killer and not recommended in most situations, but it could be interesting to see if it changes the memory usage you see in task manager.
-
As far as i know, when you do something like
GC.Collect();
your not telling the garbage collector to collect the object, your merely flagging that object for garbage collection. So when the garbage collector comes along(at a later point in time) it will collect the object you flagged. If you post your code(specifically the loop) we might be able to get the memory usage down a bit...Harvey Saayman - South Africa Junior Developer .Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111You're not flagging anything with GC.Collect. You're just telling the GC you'd LIKE a garbage collection to occur at this time. But, it's up to the GC if it wants to do it or not. When a collection runs, your app stops while the GC walks the heap looking for objects that need to be collected.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
I have a question. I have created a console application. It reads OPC Variable in loop. If I started the application, it takes about 18000K of memory. If I click at minimize button, it reduce the memory usage to 3000K. But if I call "GC.Collect()", the memory usage will not be reduced to 3000K. It happens only during minimizing. If I maximize the window again, the memory usage still at 3000K-5000K. Are there any code to reduce the memory usage without minimizing ? Because it not happens, if I call only "GC.Collect()". Thanks...
Learn how memory work under the .NET CLR. What you're seeing in Task Manager, which is a lousy place to look for memory usage by the way, you're seeing what memory the .NET CLR has reserved for your app. Your app may not be using all of this memory, but it's sitting in the .NET CLR Managed memory pool, waiting for your app to allocate some memory for objects or whatnot. When you minimize your app, the .NET CLR looks to see if there is any memory in the Managed Pool that isn't being used by your app and, from what it can tell, isn'tgoing to be used anytime soon. If so, this memory is taken out of the Managed Pool and returned to Windows. Basically, you're worried about nothing. The .NET CLR is very good at managing it's memory and cooperating with Windows. If Windows needs memory back from the .NET CLR, the CLR is more than happy to scan it's pools to see what it can return to Windows. ...entirely automatically. You don't need to do anything.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Learn how memory work under the .NET CLR. What you're seeing in Task Manager, which is a lousy place to look for memory usage by the way, you're seeing what memory the .NET CLR has reserved for your app. Your app may not be using all of this memory, but it's sitting in the .NET CLR Managed memory pool, waiting for your app to allocate some memory for objects or whatnot. When you minimize your app, the .NET CLR looks to see if there is any memory in the Managed Pool that isn't being used by your app and, from what it can tell, isn'tgoing to be used anytime soon. If so, this memory is taken out of the Managed Pool and returned to Windows. Basically, you're worried about nothing. The .NET CLR is very good at managing it's memory and cooperating with Windows. If Windows needs memory back from the .NET CLR, the CLR is more than happy to scan it's pools to see what it can return to Windows. ...entirely automatically. You don't need to do anything.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008Dave Kreskowiak wrote:
What you're seeing in Task Manager, which is a lousy place to look for memory usage by the way, you're seeing what memory the .NET CLR has reserved for your app. Your app may not be using all of this memory, but it's sitting in the .NET CLR Managed memory pool, waiting for your app to allocate some memory for objects or whatnot.
Expanding upon this; The CLR does it because asking for more memory from the kernel is an expensive operation, it's much faster to ask for a large block up front than to keep asking for little bits as needed. Also when system memory starts getting low, windows will go around asking applications if they can return extra unused memory. When this happens the same thing will occur as when you minimize the application.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall