diff --git a/ShareFileSnapIn/SyncSfItem.cs b/ShareFileSnapIn/SyncSfItem.cs index 25bc51a..b502582 100644 --- a/ShareFileSnapIn/SyncSfItem.cs +++ b/ShareFileSnapIn/SyncSfItem.cs @@ -820,8 +820,18 @@ private bool HasChildren(ShareFileClient client, Folder folder) /// private bool RemoveLocalItem(FileSystemInfo item) { - item.Delete(); - + try + { + item.Delete(); + } + catch (IOException ioe) + { + // File could not be deleted because it is locked by an object present in heap. + // Calling Garbage collector explicitly to remove the object from the heap so as to unlock and delete the file. + GC.Collect(); + GC.WaitForPendingFinalizers(); + item.Delete(); + } return true; }