Friday, September 7, 2012

Garbage Collection an sweeper in SharePoint 2010

Hi All,
Below is my finding on Garbage collection (GC). I hope it will help you all to understand in depth the SharePoint performance and memory leakage cleanup.
  1. Enumerate all BLOB files in the EBS Provider namespace that corresponds to a given SPSite identifier. Add these BLOB files to a hash table.
    String dirName = Utility.DirFromSiteId(site.ID);
    FileInfo[] files = Directory.GetFiles(dirName);
    foreach (FileInfo file in files)
    {
        ht.Add(file.Name, file);
    }
    
  2. Locate all documents in the content database that corresponds to the SPSite identifier. Remove these entries from the hash table.
    foreach (SPExternalBinaryId blobid in site.ExternalBinaryIds)
      {
        String fileName = Utility.FileFromBlobid(blobid);
            if (ht.Contains(fileName))
            {
                ht.Remove(fileName);
            }
      }
    
  3. Entries that remain in the hash table are files in the external BLOB store that do not have corresponding files in the content database. These are orphan files, and you can delete them.
    foreach (FileInfo file in ht.Values)
      {
          file.Delete();
      }

No comments: