protected virtual void Dispose(bool disposing) { if (!_isDisposed) { if (disposing) { // Dispose loaded game components for (int i = 0; i < _components.Count; i++) { var disposable = _components[i] as IDisposable; if (disposable != null) { disposable.Dispose(); } } _components = null; if (Content != null) { Content.Dispose(); Content = null; } if (_graphicsDeviceManager != null) { (_graphicsDeviceManager as GraphicsDeviceManager).Dispose(); _graphicsDeviceManager = null; } if (Platform != null) { Platform.Activated -= OnActivated; Platform.Deactivated -= OnDeactivated; _services.RemoveService(typeof(GamePlatform)); #if WINDOWS_STOREAPP Platform.ViewStateChanged -= Platform_ApplicationViewChanged; #endif Platform.Dispose(); Platform = null; } Effect.FlushCache(); ContentTypeReaderManager.ClearTypeCreators(); SoundEffect.PlatformShutdown(); BlendState.ResetStates(); DepthStencilState.ResetStates(); RasterizerState.ResetStates(); SamplerState.ResetStates(); } #if ANDROID Activity = null; #endif _isDisposed = true; _instance = null; } }