Outlook "Out of memory" error

  • Thread starter Thread starter James - SD, CA
  • Start date Start date
J

James - SD, CA

Hi Everybody,

When running a .NET app that uses Outlook Interop, we're getting this
message as an exception: "Out of memory or system resources. Close some
windows or programs and try again."

Basically, we're not sure if this is an Interop issue, an Outlook issue or
an Environment issue. Any insight anybody might have as to what could be
causing this, or even a way to attack this issue, would be greatly
appreciated.

Here's a full rundown of the situation:

We have a Windows application written in .NET that uses Outlook Interop
(we're using Outlook 2007) to process incoming emails, 24/7. The typical use
case of the system is:

1) Email is received
2) Our application polls Outlook and sees the email
3) Application saves email to file system, write some rows to a database
4) Move email (in Outlook) to a "Processed" folder

In the case of an error, email is moved to a folder in Outlook for manual
processing. The "Processed" folder described above is set to AutoArchive,
daily, moving messages older than 1 day to an archive file.

We deployed this application about 4 weeks ago, and twice, about a week and
a half apart, we got the following exception:

Message: Out of memory or system resources. Close some windows or programs
and try again.

Stack Trace: at
Microsoft.Office.Interop.Outlook.ApplicationClass.AdvancedSearch(String
Scope, Object Filter, Object SearchSubFolders, Object Tag)
at [our code that makes a call to Outlook for new messages to process]

To recover from this error, we have to stop both our application and Outlook
(including killing the OUTLOOK.exe process), and restarting both. Trying to
navigate around Outlook before restarting it results in pop up windows with
the same "Out of memory" message.

We were unable to determine the cause of this exception; the computer event
logs were of no use, as were our application's log. We have a number of
other custom applications running on the server, but none of which are
particularly memory intensive. Server is a VMware virtual machine, with a
2.66GHz processor and 2GB of RAM, running Server 2003 R2 Standard SP2. We
don't see how the memory could be spiking, on a few spot checks, the combined
memory usage for our application and Outlook never got over 120 megs. No
other app on the machine is having memory issues.

The only working theory right now is that it might be related to
AutoArchive, which archives about 500 megs of emails when it goes off.
AutoArchive needs to be done, however, as 500 megs is also the size of the
mailbox quota. We have enabled logging in Outlook, which we hope should shed
some light on this should the problem reoccur.

Again, any ideas or thoughts on attacking this issue would be greatly
appreciated!

Thanks!
James
 
It sounds to me like you're not releasing Outlook objects correctly.

Outlook connecting to an Exchange server is by default limited to 255 RPC
channels. Each object uses a connection. So does each dot operator (an
implicit object is created). In loops that runs out of channels pretty
quickly.

In addition, in .NET code, you have no way of knowing when objects will go
out of scope and be garbage collected, freeing memory and RPC channels.

So best practice dictates that you explicitly set every object to null when
no longer needed and every pass through a loop. In addition instead of using
something like _app.ActiveExplorer().Selection[1].Body you should eliminate
the dot operators and explicitly declare Explorer, Selection and item
objects so they can be explicitly released.

In addition to those measures you also have to evaluate when you release an
object if you will need its RCW again. If not then call to
Marshal.ReleaseComObject() on the object to finalize it and to inform the GC
that the object should be garbage collected. Then at the end of your
procedures you can call GC.Collect() and .WaitForPendingFinalizers().

In fact, since that may free up other objects in some cases you need to call
GC.Collect() and .WaitForPendingFinalizers() twice.




James - SD said:
Hi Everybody,

When running a .NET app that uses Outlook Interop, we're getting this
message as an exception: "Out of memory or system resources. Close some
windows or programs and try again."

Basically, we're not sure if this is an Interop issue, an Outlook issue or
an Environment issue. Any insight anybody might have as to what could be
causing this, or even a way to attack this issue, would be greatly
appreciated.

Here's a full rundown of the situation:

We have a Windows application written in .NET that uses Outlook Interop
(we're using Outlook 2007) to process incoming emails, 24/7. The typical
use
case of the system is:

1) Email is received
2) Our application polls Outlook and sees the email
3) Application saves email to file system, write some rows to a database
4) Move email (in Outlook) to a "Processed" folder

In the case of an error, email is moved to a folder in Outlook for manual
processing. The "Processed" folder described above is set to AutoArchive,
daily, moving messages older than 1 day to an archive file.

We deployed this application about 4 weeks ago, and twice, about a week
and
a half apart, we got the following exception:

Message: Out of memory or system resources. Close some windows or programs
and try again.

Stack Trace: at
Microsoft.Office.Interop.Outlook.ApplicationClass.AdvancedSearch(String
Scope, Object Filter, Object SearchSubFolders, Object Tag)
at [our code that makes a call to Outlook for new messages to process]

To recover from this error, we have to stop both our application and
Outlook
(including killing the OUTLOOK.exe process), and restarting both. Trying
to
navigate around Outlook before restarting it results in pop up windows
with
the same "Out of memory" message.

We were unable to determine the cause of this exception; the computer
event
logs were of no use, as were our application's log. We have a number of
other custom applications running on the server, but none of which are
particularly memory intensive. Server is a VMware virtual machine, with a
2.66GHz processor and 2GB of RAM, running Server 2003 R2 Standard SP2. We
don't see how the memory could be spiking, on a few spot checks, the
combined
memory usage for our application and Outlook never got over 120 megs. No
other app on the machine is having memory issues.

The only working theory right now is that it might be related to
AutoArchive, which archives about 500 megs of emails when it goes off.
AutoArchive needs to be done, however, as 500 megs is also the size of the
mailbox quota. We have enabled logging in Outlook, which we hope should
shed
some light on this should the problem reoccur.

Again, any ideas or thoughts on attacking this issue would be greatly
appreciated!

Thanks!
James
 
Back
Top