I am developing an outlook plugin.I added a button in outlook toolbar, and when the user clicks that button, a webservice is called.Depending upon the result of that webservice a usercontrol is loaded in a custom task pane.When a user closes the custom task pane, I call the dispose method on the user control.I also dispose the child control of this user control in its disposed event and removed the custom task pane from the customtaskpanes list.But the memory is not released.I also disposed the custom task pane.But nothing happened.So, is it a problem with my coding, or is it a problem with outlook?I am working with winforms on .net framework 3.5.The memory taken by outlook keeps on increasing whenever I press the button.
1
votes
Have you inspected your application with memory profiler? This will let you know what objects aren't released from memory and is your best bet to finding what actually causes the issue.
– DimitarD
I know that the user control is not getting disposed
– V K
How much time did you click the button? Maybe the garbage collector didn't decide yet to collect memory.
– Yacoub Massad
I clicked it many times.SO many times that the outlook crashed.It took memory close to 1 GB without releasing it.
– V K
1 Answers
1
votes
It is hard to tell if a memory leak occurs without any code sample. Keep in mind that analyzing managed memory can be tricky...
However, my suggestion is that you probably should not dispose your VSTO task pane controls manually. If the user clicks the hide task pane, the task pane is not "destroyed" and you should not unregister it. Its Visible property is set to false
.
See sample code below in my Startup.addin.cs that enables to Toggle the TaskPane visibility.
public const string productName = "myMillionDollarAddin";
private void RegisterTaskPane()
{
var tskControl = new TaskPaneControl();
CustomTaskPane taskPane = this.CustomTaskPanes.Add(tskControl, productName);
taskPane.Visible = true;
}
public void ShowHideTaskPane()
{
var taskPane = this.CustomTaskPanes.FirstOrDefault(ctp => ctp.Title == productName);
if (taskPane == null)
{
RegisterTaskPane();
}
else
{
var visibility = taskPane.Visible;
taskPane.Visible = !visibility;
}
}