From 9933b8a5d6e700e122e33d7da5828cb6d7ac4f5c Mon Sep 17 00:00:00 2001 From: Ryan Lai Date: Thu, 5 Dec 2019 15:41:01 -0800 Subject: [PATCH] Fix custom ops scenario tests (#2562) * Do not shutdown protobuf after ort environment gets destroyed. Lazy load lotus environment first time it is needed * comment typo * pr comment about calling phoenix singleton * Make lotus_environment static in winmladapter --- winml/adapter/WinMLAdapter.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/winml/adapter/WinMLAdapter.cpp b/winml/adapter/WinMLAdapter.cpp index 46f8c4c84b..53515e11a7 100644 --- a/winml/adapter/WinMLAdapter.cpp +++ b/winml/adapter/WinMLAdapter.cpp @@ -262,12 +262,15 @@ class WinMLAdapter : public Microsoft::WRL::RuntimeClass< Microsoft::WRL::RuntimeClassFlags, IWinMLAdapter> { private: - std::shared_ptr lotus_environment_; + // TODO: Making this static is only temporary. A fix addressing the resulting the memory leaks is needed. + static std::shared_ptr lotus_environment_; public: - WinMLAdapter() : lotus_environment_(PheonixSingleton()) { + WinMLAdapter() { + if (lotus_environment_ == nullptr) { + lotus_environment_ = PheonixSingleton(); + } } - // factory methods for creating an ort model from a path HRESULT STDMETHODCALLTYPE CreateModelProto( const char* path, @@ -644,6 +647,7 @@ class WinMLAdapter : public Microsoft::WRL::RuntimeClass< } WINML_CATCH_ALL_COM }; // namespace Windows::AI::MachineLearning::Adapter +std::shared_ptr WinMLAdapter::lotus_environment_ = nullptr; extern "C" HRESULT STDMETHODCALLTYPE OrtGetWinMLAdapter(IWinMLAdapter** adapter) try { // make an adapter instance