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); + } } }