Skip Navigation
Expand
Out of memory errors when add-ins are configured
Answer ID 6650   |   Last Review Date 12/18/2018

Why are agents getting frequent 'Out of Memory' errors?

Environment:

Add-ins, Agent Console > Out of Memory errors when add-ins are present

Issue:

We are getting Out of Memory errors randomly and have add-ins included in our desktop configuration. The code in the add-ins contains IGlobalContext to obtain an IAutomationcontext reference. Using IGlobalContext.IAutomationContext to subscribe and unsubscribe to events can cause unsubscribe events to not be handled by the framework. This is the correct flow, however there is a slight caveat. Everytime IGlobalContext.IAutomationContext is used a new AddInSideAdapter will be created to reference the AutomationContext. In practice, you wire up the event like this:

IGlobalContext.AutomationContext.CurrentEditorTabChanged += eventHandler;
IGlobalContext.AutomationContext.CurrentEditorTabChanged -= eventHandler;

In this example, you are not actually unwiring the event in the second line that you wired up in the first line. IGlobalContext.AutomationContext is not static nor a singleton.

Resolution:

The proper way to do this would be to set your AutomationContext to a local variable to ensure that you are always referencing the same object. For example:

private IAutomationContext intitialAutomationContext;
intitialAutomationContext = globalContext.AutomationContext;

intitialAutomationContext .CurrentEditorTabChanged += eventHandler;
intitialAutomationContext .CurrentEditorTabChanged -= eventHandler;

In this case the event will be unsubscribed properly.

Cause:

Everytime IGlobalContext.IAutomationContext is used a new AddInSideAdapter is created to reference the AutomationContext. IGlobalContext.AutomationContext is not static nor a singleton.