开发者

asp.net interop memory limitation

开发者 https://www.devze.com 2023-01-21 09:31 出处:网络
I have an asp.net app which uses legacy COM interop library.Works fine until mem开发者_运维知识库ory reaches somewhere around 500Mb and then it is no longer able to create new COM objects (get various

I have an asp.net app which uses legacy COM interop library. Works fine until mem开发者_运维知识库ory reaches somewhere around 500Mb and then it is no longer able to create new COM objects (get various exceptions, e.g. Creating an instance of the COM component with CLSID {FFFF-FFFF-FFFF-FFF-FFFFFF} from the IClassFactory failed due to the following error: 80070008.). It almost looks like it is hitting some kind of memory limit, but what is it? Can it be changed?

Solved! Turns out the object was creating a Window handle and we were hitting the 10K Window handles limit (except it was happening at 2K instances for some reason when inside IIS)


Solved! Turns out the object was creating a Window handle and we were hitting the 10K Window handles limit (except it was happening at 2K instances for some reason when inside IIS)


What OS, and is it 32-bit or 64-bit? What are you using to determine memory usage?

When you say you're explicitly releasing the objects, do you mean you're using Marshal.ReleaseComObject()?

I'm assuming you have AspCompat=true in your <%@ Page > tag... wouldn't expect it to run at all if you didn't.

Can you give us some details on your COM object; what does it do, and can you post some code where you're calling it, including COM object signatures? How much memory would you expect a single object to take?

My first suspect, based only on the information that I've read so far, is that 500Mb is not truly the total memory in use, and/or that you're having a memory fragmentation issue. I've seen this occur with IIS processes when less than half of the memory is in use, and the errors tend to be random, depending on what object is being created at the time. BTW, 80070008 is 'not enough storage space'.

Process limits are 2GB on a 32-bit machine, of course, but even if a process isn't using the full 2GB, if there's not a contiguous block of memory of the size needed when creating an object, you'll get an out-of-memory error when you try to allocate. Lots of concurrent users implies lots of COM objects (and other objects) being allocated and released in a short period of time... which points to fragmentation as a suspect.

Coming up with an attack plan requires more info about the COM object and how it's being used.


Use a command pattern for queueing and executing the com interop in an asynchronous thread. This can free up the number of threads being used by iis, and allow you to control the number of calls/instances of the com app.


You may think about object pooling rather than creating every time a new object.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号