From 280625afb4b24557a2a405340a2aa6b93d457d6e Mon Sep 17 00:00:00 2001 From: v-didara Date: Thu, 6 Nov 2014 18:56:51 -0800 Subject: [PATCH] Implementing IDisposable interface for PersistentVM class as it is causing OOM exceptions. --- .../Model/PersistentVM.cs | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs b/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs index 7f1ba15db..d6d2227ca 100644 --- a/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs +++ b/src/ServiceManagement/Compute/Commands.ServiceManagement/Model/PersistentVM.cs @@ -12,6 +12,7 @@ // limitations under the License. // ---------------------------------------------------------------------------------- +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Security.Cryptography.X509Certificates; @@ -19,7 +20,7 @@ namespace Microsoft.WindowsAzure.Commands.ServiceManagement.Model { - public class PersistentVM : IPersistentVM + public class PersistentVM : IPersistentVM,IDisposable { public string AvailabilitySetName { @@ -131,6 +132,33 @@ public PersistentVM GetInstance() { return this; } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + //Free managed resources + ResourceExtensionReferences = null; + DataVirtualHardDisksToBeDeleted = null; + X509Certificates = null; + WinRMCertificate = null; + ConfigurationSets = null; + DataVirtualHardDisks = null; + OSVirtualHardDisk = null; + } + //Free unmanaged resources + } + + ~PersistentVM() + { + Dispose(false); + } } }