How to lure OutOfMemoryException in .NET (Excel add-in)

I get an OutOfMemory exception in my .net addin. Addin uses a large number of managed and unmanaged objects. Is there any way to catch this exception?

Updated: I think that any application can get an OutofMemory exception if it processes a large amount of data that needs to be processed and not freed periodically. Suppose I have a method that parses some structures in memory. I give him 300 structures, he loads each of them into memory, analyzes them and completes the processing. In this operation, the memory usage was X. Now, if I give 3,000 structures for processing, it will analyze these 3,000 in memory, and the memory usage will go up to 10X.

Update

This problem is only observed in Excel 2007 and not in Excel 2003, and why I asked the MSDN staff to study it.

+3
source share
3 answers

In .Net, an OutOfMemoryException is thrown at runtime when it cannot allocate the requested memory for your application. Thus, there is very little actual work that can be done to handle such an exception.

Instead of catching him, you should stop him first. Ignoring the exception will not make the problem go away.

+3
source

If you get an OutOfMemoryException, your program has died, ceased to exist, passed on, is gone and gone to meet its creator.

, , , .

0

It may be a garbage collector. Try to force the collection periodically.

If this does not help, read the following: http://www.simple-talk.com/dotnet/.net-framework/the-dangers-of-the-large-object-heap/

0
source

Source: https://habr.com/ru/post/1706871/


All Articles