From ac56b301b4357c717d8f3518978680f171c4719c Mon Sep 17 00:00:00 2001
From: Patrick Simpson
Date: Tue, 7 Feb 2017 14:45:34 +0100
Subject: [PATCH] Small cleanup to folder item iteration
---
.../Stubs/OutlookWrappers/FolderWrapper.cs | 24 +++++++++++--------
.../AcaciaZPushPlugin/Utils/ComRelease.cs | 2 +-
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs
index a89df4d..944d122 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Stubs/OutlookWrappers/FolderWrapper.cs
@@ -139,11 +139,7 @@ namespace Acacia.Stubs.OutlookWrappers
{
get
{
- if (_last != null)
- {
- _last.Dispose();
- _last = default(ItemType);
- }
+ CleanLast();
_last = Mapping.Wrap(_enum.Current);
return _last;
}
@@ -157,12 +153,23 @@ namespace Acacia.Stubs.OutlookWrappers
}
}
+ private void CleanLast()
+ {
+ if (_last != null)
+ {
+ _last.Dispose();
+ _last = default(ItemType);
+ }
+ }
+
public void Dispose()
{
+ CleanLast();
if (_enum != null)
{
if (_enum is IDisposable)
((IDisposable)_enum).Dispose();
+ ComRelease.Release(_enum);
_enum = null;
}
if (_items != null)
@@ -174,16 +181,13 @@ namespace Acacia.Stubs.OutlookWrappers
public bool MoveNext()
{
- if (_last != null)
- {
- _last.Dispose();
- _last = default(ItemType);
- }
+ CleanLast();
return _enum.MoveNext();
}
public void Reset()
{
+ CleanLast();
_enum.Reset();
}
}
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/ComRelease.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/ComRelease.cs
index f056582..b20488d 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/ComRelease.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Utils/ComRelease.cs
@@ -59,7 +59,7 @@ namespace Acacia.Utils
{
if (!Enabled)
return;
- if (o == null)
+ if (o == null || !Marshal.IsComObject(o))
return;
if (Logger.Instance.IsLevelEnabled(LogLevel.TraceExtra))