Don't use the shared_ptr initialDefaultWireFormat_. Use gotInitialDefaultWireFormat instead.
diff --git a/ndn-cpp/encoding/WireFormat.cpp b/ndn-cpp/encoding/WireFormat.cpp
index e208b82..56f37d3 100644
--- a/ndn-cpp/encoding/WireFormat.cpp
+++ b/ndn-cpp/encoding/WireFormat.cpp
@@ -10,18 +10,17 @@
namespace ndn {
-ptr_lib::shared_ptr<WireFormat> WireFormat::initialDefaultWireFormat_;
+static bool gotInitialDefaultWireFormat = false;
WireFormat *WireFormat::defaultWireFormat_ = 0;
WireFormat *WireFormat::getDefaultWireFormat()
{
- if (!defaultWireFormat_ && !initialDefaultWireFormat_) {
+ if (!defaultWireFormat_ && !gotInitialDefaultWireFormat) {
// There is no defaultWireFormat_ and we have not yet initialized initialDefaultWireFormat_, so initialize and use it.
- // NOTE: This could have been done with a static initializer on initialDefaultWireFormat_, but this does not have
- // good cross-platform support, especially for dynamic shared libraries.
- initialDefaultWireFormat_.reset(newInitialDefaultWireFormat());
- defaultWireFormat_ = initialDefaultWireFormat_.get();
+ gotInitialDefaultWireFormat = true;
+ // NOTE: This allocates one object which we never free for the life of the application.
+ defaultWireFormat_ = newInitialDefaultWireFormat();
}
return defaultWireFormat_;
diff --git a/ndn-cpp/encoding/WireFormat.hpp b/ndn-cpp/encoding/WireFormat.hpp
index fb4b9c2..32bf82f 100644
--- a/ndn-cpp/encoding/WireFormat.hpp
+++ b/ndn-cpp/encoding/WireFormat.hpp
@@ -48,11 +48,6 @@
*/
static WireFormat *newInitialDefaultWireFormat();
- /**
- * Hold the result of newInitialDefaultWireFormat in this shared_ptr which is freed when the application exits.
- */
- static ptr_lib::shared_ptr<WireFormat> initialDefaultWireFormat_;
-
static WireFormat *defaultWireFormat_;
};