From fb5082a11a4331a10abaa0e3e7ba1567e62a0606 Mon Sep 17 00:00:00 2001 From: WonYoung Choi Date: Tue, 26 Apr 2016 19:10:41 +0900 Subject: [PATCH] Implement IDisposable of Appliation class Change-Id: I1105e11b4473438cdfca717281a71067f9b9da26 --- .../Tizen.Applications/Application.cs | 67 +++++++++++++++++----- 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/Tizen.Applications/Tizen.Applications/Application.cs b/Tizen.Applications/Tizen.Applications/Application.cs index f4ee478..b208f05 100755 --- a/Tizen.Applications/Tizen.Applications/Application.cs +++ b/Tizen.Applications/Tizen.Applications/Application.cs @@ -15,7 +15,7 @@ namespace Tizen.Applications /// /// The Application handles an application state change or system events and provides mechanisms that launch other applications. /// - public abstract class Application + public abstract class Application : IDisposable { private const string LogTag = "Tizen.Applications"; @@ -88,19 +88,11 @@ namespace Tizen.Applications { if (_applicationInfo == null) { - string appId; - ErrorCode err = Interop.AppCommon.AppGetId(out appId); - if (err == ErrorCode.None) + string appId = string.Empty; + Interop.AppCommon.AppGetId(out appId); + if (!string.IsNullOrEmpty(appId)) { - try - { - // TODO: Use lazy enabled AppInfo class without throwing exceptions. - _applicationInfo = ApplicationManager.GetInstalledApplication(appId); - } - catch (Exception e) - { - Log.Warn(LogTag, "Failed to get application info. " + e.Message); - } + _applicationInfo = new ApplicationInfo(appId); } } } @@ -225,5 +217,54 @@ namespace Tizen.Applications } b.Dispose(); } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + /// + /// Releases any unmanaged resources used by this object. Can also dispose any other disposable objects. + /// + /// If true, disposes any disposable objects. If false, does not dispose disposable objects. + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + if (_applicationInfo != null) + { + _applicationInfo.Dispose(); + } + if (_lowMemoryNativeHandle != null && !_lowMemoryNativeHandle.IsInvalid) + { + _lowMemoryNativeHandle.Dispose(); + } + if (_localeChangedNativeHandle != null && !_localeChangedNativeHandle.IsInvalid) + { + _localeChangedNativeHandle.Dispose(); + } + } + + disposedValue = true; + } + } + + /// + /// Finalizer of the Application class. + /// + ~Application() + { + Dispose(false); + } + + /// + /// Releases all resources used by the Application class. + /// + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + #endregion } } -- 2.7.4