Problem in memory usage in .net
-
Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks
-
Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks
Kim0618 wrote:
After the program is running for a long time by user interactions, its memory usage will increase to the limit
This is not good, I suspect that somewhere maybe stuff gets put into a collection of some kind and never removed. I suggest getting a memory profiler to point out these flaws for you. Hope you figure it out
Harvey Saayman - South Africa Software Developer .Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
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 -
Kim0618 wrote:
After the program is running for a long time by user interactions, its memory usage will increase to the limit
This is not good, I suspect that somewhere maybe stuff gets put into a collection of some kind and never removed. I suggest getting a memory profiler to point out these flaws for you. Hope you figure it out
Harvey Saayman - South Africa Software Developer .Net, C#, SQL
you.suck = (you.Occupation == jobTitles.Programmer && you.Passion != Programming)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111Agreed. Don't understand why anyone would vote that a bad answer. Something which just keeps growing over time needs reviewing.
Regards, Rob Philpott.
-
Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks
You're probably not disposing of something properly, or you're not maintaining a collection of object properly, or any number of other causes. You need to look at your app run with a profiler to find out what's going on. This is something that you should have been testing for before it got deployed to production.
Kim0618 wrote:
I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively.
This has nothing to do with the GC's inability to do it's job. It can still do it's job very effectively, even on the most complex of applications.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Hi, I have written a complex program in c#.net. After the program is running for a long time by user interactions, its memory usage will increase to the limit of the system, then error will occur. How can the program alert the user that the memory usage is nearly close to its limit before it goes into error ? I have tried memory garbage collection but the program is too complex that garbage collection cannot clean up the memory usage effectively. Thanks
There are many ways to run out of memory. The most obvious one is keeping things around that you no longer need but for some reason still hold on to. .NET sometimes has a problem with the "large object heap" (LOH) which never gets compacted, and may run out of space. A popular culprit is a collection growing larger and larger. As soon as it hold 20,000+ objects, the reference array is a large object (as it exceeds 80KB); any time it needs more capacity, it gets reallocated with twice its size. The space occupied by the old array is freed, but will not be reused by that same array as it keeps growing. Of course the objects themselves in the collection also take memory; that may or may not come from the LOH, depending on their size. If, I don't know you do, but if you are building a cache of some sort, you should keep its size in check, and probably use WeakReference techniques. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Happy New Year to all.
We hope 2010 soon brings us automatic PRE tags!
Until then, please insert them manually.
-
There are many ways to run out of memory. The most obvious one is keeping things around that you no longer need but for some reason still hold on to. .NET sometimes has a problem with the "large object heap" (LOH) which never gets compacted, and may run out of space. A popular culprit is a collection growing larger and larger. As soon as it hold 20,000+ objects, the reference array is a large object (as it exceeds 80KB); any time it needs more capacity, it gets reallocated with twice its size. The space occupied by the old array is freed, but will not be reused by that same array as it keeps growing. Of course the objects themselves in the collection also take memory; that may or may not come from the LOH, depending on their size. If, I don't know you do, but if you are building a cache of some sort, you should keep its size in check, and probably use WeakReference techniques. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Happy New Year to all.
We hope 2010 soon brings us automatic PRE tags!
Until then, please insert them manually.
-
Thanks for your answer ! But what is the weak reference technique that you have mentioned ?
You're welcome. You might want and read up on WeakReference class. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Happy New Year to all.
We hope 2010 soon brings us automatic PRE tags!
Until then, please insert them manually.