|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Memory ManagementI have written an application that processes large images and therefore uses a lot of memory. Due to the fact that this application suppose to be widely distributed I need to control the memory consumption, I release all objects when no long in use and I call the garbage collector (passing 2 [for 2nd generation] as a parameter) often. The results that I get is not satisfactory and I wonder what can be done to actually force the system to free all memory taken and no longer in use. I noticed that when I run another application at the same time and the other application took an extreme amount of memory (600mb) my application's memory use went down to 16mb (from 40-50mb). Can I cause that to happen from within the application (It seems that .NET releases memory in 1 application when another application is requiring memory). It also proved that there is no memory leak in my application Thank you in advance , Samuel Samuel wrote:
> [...] This suggests that you are in fact freeing the memory you need to free.> I noticed that when I run another application at the same time and the other > application took an extreme amount of memory (600mb) my application's memory > use went down to 16mb (from 40-50mb). I also wonder how it is that in this day and age you might think that a 40-50MB working set is in any way large. :) > Can I cause that to happen from within the application (It seems that .NET If you're sure there's no memory leak, then it sounds to me as though > releases memory in 1 application when another application is requiring > memory). It also proved that there is no memory leak in my application you've done everything you need to (and perhaps more, in fact). If your application does not interfere with other memory-hungry applications on the computer, then that is all you need to do. Anything beyond that is more likely to interfere with Windows' attempt to manage memory efficiently, resulting in _poorer_ performance than if you simply did nothing. Pete The 40-50 figure is not the woory, it may go to as high as 150 or 200
Show quote "Peter Duniho" <NpOeStPe***@NnOwSlPiAnMk.com> wrote in message news:13ha3cubeg91p30@corp.supernews.com... > Samuel wrote: >> [...] >> I noticed that when I run another application at the same time and the >> other application took an extreme amount of memory (600mb) my >> application's memory use went down to 16mb (from 40-50mb). > > This suggests that you are in fact freeing the memory you need to free. > > I also wonder how it is that in this day and age you might think that a > 40-50MB working set is in any way large. :) > >> Can I cause that to happen from within the application (It seems that >> .NET releases memory in 1 application when another application is >> requiring memory). It also proved that there is no memory leak in my >> application > > If you're sure there's no memory leak, then it sounds to me as though > you've done everything you need to (and perhaps more, in fact). If your > application does not interfere with other memory-hungry applications on > the computer, then that is all you need to do. Anything beyond that is > more likely to interfere with Windows' attempt to manage memory > efficiently, resulting in _poorer_ performance than if you simply did > nothing. > > Pete Samuel wrote:
> The 40-50 figure is not the woory, it may go to as high as 150 or 200 Even 200MB isn't an issue.Regardless, from everything you've written so far it doesn't sound to me as though there's an actual problem. When there's memory pressure from other processes on the computer, the memory usage of your own application is appropriately reduced and your own application does not appear to interfere with other processes. If you feel it's still a concern, you should post more specifics. Especially you should describe how it is you are monitoring memory usage in the first place. Jason's comments about Task Manager and monitoring memory usage generally are accurate and you'll want to consider those issues before wasting a lot of time dealing with this "issue". Pete I will certainly look into Jason's comments but what worries me is that some
of the systems are just getting slow Show quote "Peter Duniho" <NpOeStPe***@NnOwSlPiAnMk.com> wrote in message news:13ha9hta1gmpm9c@corp.supernews.com... > Samuel wrote: >> The 40-50 figure is not the woory, it may go to as high as 150 or 200 > > Even 200MB isn't an issue. > > Regardless, from everything you've written so far it doesn't sound to me > as though there's an actual problem. When there's memory pressure from > other processes on the computer, the memory usage of your own application > is appropriately reduced and your own application does not appear to > interfere with other processes. > > If you feel it's still a concern, you should post more specifics. > Especially you should describe how it is you are monitoring memory usage > in the first place. Jason's comments about Task Manager and monitoring > memory usage generally are accurate and you'll want to consider those > issues before wasting a lot of time dealing with this "issue". > > Pete Samuel wrote:
> I will certainly look into Jason's comments but what worries me is that some "Slow" isn't necessarily your application's fault, or something you can > of the systems are just getting slow do anything about. You need to determine _why_ things are "slow" first. As an example of a situation you can do nothing about: it is not uncommon, especially on computers with relatively little installed system memory, for an application that itself has a large memory footprint to cause other process data to be swapped out to disk while that application is working. You can free the memory, but typically the other data isn't going to come back into system memory right away. So when the user switches back to some other application, all that data that was swapped out has to be read back into system memory. There's nothing you can do about that. Releasing your own data isn't sufficient. The OS at some point simply has to read all that other data back in, and that's going to be "slow". Is this the problem you're dealing with? I have no idea. Your problem description so far is simply "slow", which isn't really much to go on. But the kinds of things you are talking about trying to do in order to deal with memory management issues are not generally things that a normal application would need to do, or would gain any advantage by doing. And so far, your application sure sounds "normal". Pete If you're using task manager for reference, it can be misleading. You
need to google some about it. There are a ton of conversations about it. http://www.itwriting.com/dotnetmem.php http://www.ddj.com/windows/184416804 What you see in task manager can be controlled via EmptyWorkingSet() or SetProcessWorkingSetSize() API calls but it is discouraged. You'll see the same affect if you minimize your application. Jason Newell www.jasonnewell.net Samuel wrote: Show quote > Hi > > I have written an application that processes large images and therefore uses > a lot of memory. > > Due to the fact that this application suppose to be widely distributed I > need to control the memory consumption, I release all objects when no long > in use and I call the garbage collector (passing 2 [for 2nd generation] as a > parameter) often. > > The results that I get is not satisfactory and I wonder what can be done to > actually force the system to free all memory taken and no longer in use. > > I noticed that when I run another application at the same time and the other > application took an extreme amount of memory (600mb) my application's memory > use went down to 16mb (from 40-50mb). > Can I cause that to happen from within the application (It seems that .NET > releases memory in 1 application when another application is requiring > memory). It also proved that there is no memory leak in my application > > Thank you in advance , > Samuel > > Hello,
calling GC.Collect will disturb internal statistics of the GC and will most likely lead to poorer performance. If memory pressure is high, the GC will automatically release the memory. On option might be to use unmanaged memory for large images. AFAIK, Paint.NET uses unmanaged memory for images. Kind regards, Henning Krause Show quote "Samuel" <samuel.shul***@ntlworld.com> wrote in message news:%23AP1KdCEIHA.4228@TK2MSFTNGP02.phx.gbl... > Hi > > I have written an application that processes large images and therefore > uses a lot of memory. > > Due to the fact that this application suppose to be widely distributed I > need to control the memory consumption, I release all objects when no long > in use and I call the garbage collector (passing 2 [for 2nd generation] as > a parameter) often. > > The results that I get is not satisfactory and I wonder what can be done > to actually force the system to free all memory taken and no longer in > use. > > I noticed that when I run another application at the same time and the > other application took an extreme amount of memory (600mb) my > application's memory use went down to 16mb (from 40-50mb). > Can I cause that to happen from within the application (It seems that .NET > releases memory in 1 application when another application is requiring > memory). It also proved that there is no memory leak in my application > > Thank you in advance , > Samuel > Samuel wrote:
> Hi How are you releasing them? If the objects implement IDisposable, you > > I have written an application that processes large images and therefore uses > a lot of memory. > > Due to the fact that this application suppose to be widely distributed I > need to control the memory consumption, I release all objects when no long > in use should call the Dispose method when you are done with them. Be ware of small objects that might not seem like they need disposing, like Brush and Font. They contain windows handles, and if you don't dispose them you might run out of windows resources. > and I call the garbage collector (passing 2 [for 2nd generation] as a There is normally no reason at all to force a garbage collection. The > parameter) often. garbage collector will do that when needed. Also, the garbage collector can choose a better time to run garbage collections if you leave it be. > The results that I get is not satisfactory and I wonder what can be done to You can't and you don't need to.> actually force the system to free all memory taken and no longer in use. > I noticed that when I run another application at the same time and the other That's because the garbage collector kicks in when needed. There is no > application took an extreme amount of memory (600mb) my application's memory > use went down to 16mb (from 40-50mb). reason to do a lot of work to free memory when it's not needed for anything else. |
|||||||||||||||||||||||