简体   繁体   中英

What happens when memory will be full?

I am working on a C# WPF application which uses pixel data from many images to process one image.
It stores every image as System.Drawing.Bitmap and are locked into memory.
The user is able to open any number of images.

The question is that what should normally happen when the user opens so many images, that the memory will be full during processing?

On my Windows 8.1 computer, when this happens, I see in task manager that the memory usage is getting higher, it slows down, and freezes for a minute, then the application exits.

However, on my Windows 8.1 (non-RT) tablet, when this happens, I see in task manager that the memory usage is getting higher then suddenly gets low and then getting higher again and so on for 2-3 times... (this is very strange for me because I think all images should be kept in memory and only released from memory when no longer needed), the speed is normal, no freeze, and AccessViolationException occurs.

So I would like to know if these behaviors are normal or not, and if not what is the normal behavior and why is it not normal for me?

C# is not a good language for memory hungry applications. So like a suggession I would say:

  • Validate do you really need all images in memory contemporary to process or you need only 2, or some part of them in memory, contemporary.

  • if the answer is yes, you may look for MemoryMapped files.

  • if the answer is no, rearchitect your code.

To answer your question: no it's not a normal behaviour and the only right way to deal with memory consumption that leads to some application undefined behavior, is to fix the architecture of application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM