http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqQuery.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqQuery.cpp b/src/clicache/src/CqQuery.cpp
index eb50ad7..25c93d9 100644
--- a/src/clicache/src/CqQuery.cpp
+++ b/src/clicache/src/CqQuery.cpp
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-//#include "geode_includes.hpp"
+
 #include "CqQuery.hpp"
 #include "Query.hpp"
 #include "CqAttributes.hpp"
@@ -34,6 +34,7 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       generic<class TKey, class TResult>
       ICqResults<TResult>^ CqQuery<TKey, TResult>::ExecuteWithInitialResults()
@@ -45,30 +46,21 @@ namespace Apache
       ICqResults<TResult>^ CqQuery<TKey, 
TResult>::ExecuteWithInitialResults(System::UInt32 timeout)
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-
-          apache::geode::client::CqResultsPtr& nativeptr =
-            NativePtr->executeWithInitialResults(timeout);
-          if (nativeptr.get() == NULL) return nullptr;
-
-          apache::geode::client::ResultSet* resultptr = 
dynamic_cast<apache::geode::client::ResultSet*>(
-            nativeptr.ptr( ) );
-          if ( resultptr == NULL )
+          try
           {
-            apache::geode::client::StructSet* structptr = 
dynamic_cast<apache::geode::client::StructSet*>(
-              nativeptr.ptr( ) );
-            if ( structptr == NULL )
+            auto nativeptr = 
m_nativeptr->get()->executeWithInitialResults(timeout);
+ 
+            if (auto structptr = 
std::dynamic_pointer_cast<native::StructSet>(nativeptr))
             {
-              return nullptr;
+              return StructSet<TResult>::Create(structptr);
             }
-            return StructSet<TResult>::Create(structptr);
+
+            return nullptr;
           }
-          /*else
+          finally
           {
-            return ResultSet::Create(resultptr);
-          }*/
-
-          return nullptr;
-
+            GC::KeepAlive(m_nativeptr);
+          }
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
@@ -77,7 +69,14 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          NativePtr->execute();
+          try
+          {
+            m_nativeptr->get()->execute();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -85,59 +84,103 @@ namespace Apache
       generic<class TKey, class TResult>
       String^ CqQuery<TKey, TResult>::QueryString::get( )
       {
-        return ManagedString::Get( NativePtr->getQueryString( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getQueryString( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TResult>
       String^ CqQuery<TKey, TResult>::Name::get( )
       {
-        return ManagedString::Get( NativePtr->getName( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getName( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TResult>
       Query<TResult>^ CqQuery<TKey, TResult>::GetQuery( )
       {
-        return Query<TResult>::Create(NativePtr->getQuery().get());
+        try
+        {
+          return Query<TResult>::Create(m_nativeptr->get()->getQuery());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TResult>
       CqAttributes<TKey, TResult>^ CqQuery<TKey, TResult>::GetCqAttributes( )
       {
-        return CqAttributes<TKey, TResult>::Create(NativePtr->getCqAttributes( 
).get());
+        try
+        {
+          return CqAttributes<TKey, 
TResult>::Create(m_nativeptr->get()->getCqAttributes( ));
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TResult>
       CqAttributesMutator<TKey, TResult>^ CqQuery<TKey, 
TResult>::GetCqAttributesMutator( )
       {
-        return CqAttributesMutator<TKey, 
TResult>::Create(NativePtr->getCqAttributesMutator().get());
+        try
+        {
+          return CqAttributesMutator<TKey, 
TResult>::Create(m_nativeptr->get()->getCqAttributesMutator());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TResult>
       CqStatistics^ CqQuery<TKey, TResult>::GetStatistics( )
       {
-        return CqStatistics::Create(NativePtr->getStatistics().get());
+        try
+        {
+          return CqStatistics::Create(m_nativeptr->get()->getStatistics());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TResult>
       CqStateType CqQuery<TKey, TResult>::GetState( )
       {
-        apache::geode::client::CqState::StateType st =  NativePtr->getState( );
-        CqStateType state;
-        switch (st)
+        try
         {
-          case apache::geode::client::CqState::STOPPED: {
+          auto st = m_nativeptr->get()->getState();
+          CqStateType state;
+          switch (st)
+          {
+          case native::CqState::STOPPED: {
             state = CqStateType::STOPPED;
             break;
           }
-          case apache::geode::client::CqState::RUNNING: {
+          case native::CqState::RUNNING: {
             state = CqStateType::RUNNING;
             break;
           }
-          case apache::geode::client::CqState::CLOSED: {
+          case native::CqState::CLOSED: {
             state = CqStateType::CLOSED;
             break;
           }
-          case apache::geode::client::CqState::CLOSING: {
+          case native::CqState::CLOSING: {
             state = CqStateType::CLOSING;
             break;
           }
@@ -145,8 +188,13 @@ namespace Apache
             state = CqStateType::INVALID;
             break;
           }
+          }
+          return state;
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
         }
-        return state;
       }
 
       generic<class TKey, class TResult>
@@ -154,7 +202,14 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          NativePtr->stop( );
+          try
+          {
+            m_nativeptr->get()->stop( );
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -164,7 +219,14 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          NativePtr->close( );
+          try
+          {
+            m_nativeptr->get()->close( );
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -174,7 +236,14 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          return NativePtr->isRunning( );
+          try
+          {
+            return m_nativeptr->get()->isRunning( );
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -184,21 +253,34 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          return NativePtr->isStopped( );
+          try
+          {
+            return m_nativeptr->get()->isStopped( );
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
       generic<class TKey, class TResult>
-      bool CqQuery<TKey, TResult>::IsClosed( )
-      {
-        _GF_MG_EXCEPTION_TRY2/* due to auto replace */
+        bool CqQuery<TKey, TResult>::IsClosed()
+        {
+          _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          return NativePtr->isClosed( );
+            try
+          {
+            return m_nativeptr->get()->isClosed();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
-        _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+          _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
+      }
     }  // namespace Client
   }  // namespace Geode
 }  // namespace Apache
-
- } //namespace 

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqQuery.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqQuery.hpp b/src/clicache/src/CqQuery.hpp
index 97f3d47..8cbf9f8 100644
--- a/src/clicache/src/CqQuery.hpp
+++ b/src/clicache/src/CqQuery.hpp
@@ -19,8 +19,10 @@
 
 #include "geode_defs.hpp"
 #include "CqState.hpp"
+#include "begin_native.hpp"
 #include <geode/CqQuery.hpp>
-//#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+#include "native_shared_ptr.hpp"
 
 
 using namespace System;
@@ -31,6 +33,7 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       generic<class TResult>
       interface class ICqResults;
@@ -63,7 +66,6 @@ namespace Apache
       /// </remarks>
       generic<class TKey, class TResult>
       public ref class CqQuery sealed
-        : public Internal::SBWrap<apache::geode::client::CqQuery>
       {
       public:
 
@@ -166,13 +168,10 @@ namespace Apache
         /// <returns>
         /// The managed wrapper object; null if the native pointer is null.
         /// </returns>
-        inline static CqQuery<TKey, TResult>^ Create( 
apache::geode::client::CqQuery* nativeptr )
+        inline static CqQuery<TKey, TResult>^ Create( native::CqQueryPtr 
nativeptr )
         {
-          if (nativeptr == nullptr)
-          {
-            return nullptr;
-          }
-          return gcnew CqQuery<TKey, TResult>( nativeptr );
+          return __nullptr == nativeptr ? nullptr :
+            gcnew  CqQuery<TKey, TResult>( nativeptr );
         }
 
 
@@ -182,8 +181,13 @@ namespace Apache
         /// Private constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline CqQuery( apache::geode::client::CqQuery* nativeptr )
-          : SBWrap( nativeptr ) { }
+        inline CqQuery( native::CqQueryPtr nativeptr )
+        {
+          m_nativeptr = gcnew native_shared_ptr<native::CqQuery>(nativeptr);
+        }
+
+
+         native_shared_ptr<native::CqQuery>^ m_nativeptr;
       };
     }  // namespace Client
   }  // namespace Geode

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqServiceStatistics.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqServiceStatistics.cpp 
b/src/clicache/src/CqServiceStatistics.cpp
index c52a85c..6a9da4c 100644
--- a/src/clicache/src/CqServiceStatistics.cpp
+++ b/src/clicache/src/CqServiceStatistics.cpp
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-//#include "geode_includes.hpp"
 #include "CqServiceStatistics.hpp"
 
 
@@ -25,28 +24,63 @@ namespace Apache
   {
     namespace Client
     {
+      using namespace System;
 
-       System::UInt32 CqServiceStatistics::numCqsActive( )
-       {
-         return NativePtr->numCqsActive( );
-       }
-    System::UInt32 CqServiceStatistics::numCqsCreated( )
-       {
-         return NativePtr->numCqsCreated( );
-       }
-    System::UInt32 CqServiceStatistics::numCqsClosed( )
-       {
-         return NativePtr->numCqsClosed( );
-       }
-    System::UInt32 CqServiceStatistics::numCqsStopped( )
-       {
-         return NativePtr->numCqsStopped( );
-       }
-    System::UInt32 CqServiceStatistics::numCqsOnClient( )
-       {
-         return NativePtr->numCqsOnClient( );
+      System::UInt32 CqServiceStatistics::numCqsActive()
+      {
+        try
+        {
+          return m_nativeptr->get()->numCqsActive();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+      System::UInt32 CqServiceStatistics::numCqsCreated()
+      {
+        try
+        {
+          return m_nativeptr->get()->numCqsCreated();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+      System::UInt32 CqServiceStatistics::numCqsClosed()
+      {
+        try
+        {
+          return m_nativeptr->get()->numCqsClosed();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+      System::UInt32 CqServiceStatistics::numCqsStopped()
+      {
+        try
+        {
+          return m_nativeptr->get()->numCqsStopped();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+      System::UInt32 CqServiceStatistics::numCqsOnClient()
+      {
+        try
+        {
+          return m_nativeptr->get()->numCqsOnClient();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
     }  // namespace Client
   }  // namespace Geode
 }  // namespace Apache
-
- } //namespace 

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqServiceStatistics.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqServiceStatistics.hpp 
b/src/clicache/src/CqServiceStatistics.hpp
index fc8f235..d711d8a 100644
--- a/src/clicache/src/CqServiceStatistics.hpp
+++ b/src/clicache/src/CqServiceStatistics.hpp
@@ -18,9 +18,10 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/CqServiceStatistics.hpp>
-#include "impl/NativeWrapper.hpp"
-
+#include "end_native.hpp"
+#include "native_shared_ptr.hpp"
 
 namespace Apache
 {
@@ -28,12 +29,12 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       /// <summary>
       /// Defines common statistical information for cqservice 
       /// </summary>
       public ref class CqServiceStatistics sealed
-        : public Internal::SBWrap<apache::geode::client::CqServiceStatistics>
       {
       public:
 
@@ -75,13 +76,10 @@ namespace Apache
         /// <returns>
         /// The managed wrapper object; null if the native pointer is null.
         /// </returns>
-        inline static CqServiceStatistics^ Create( 
apache::geode::client::CqServiceStatistics* nativeptr )
+        inline static CqServiceStatistics^ Create( 
apache::geode::client::CqServiceStatisticsPtr nativeptr )
         {
-          if (nativeptr == nullptr)
-          {
-            return nullptr;
-          }
-          return gcnew CqServiceStatistics( nativeptr );
+          return __nullptr == nativeptr ? nullptr :
+            gcnew CqServiceStatistics( nativeptr );
         }
 
 
@@ -91,8 +89,12 @@ namespace Apache
         /// Private constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline CqServiceStatistics( 
apache::geode::client::CqServiceStatistics* nativeptr )
-          : SBWrap( nativeptr ) { }
+        inline CqServiceStatistics( 
apache::geode::client::CqServiceStatisticsPtr nativeptr )
+        {
+          m_nativeptr = gcnew 
native_shared_ptr<native::CqServiceStatistics>(nativeptr);
+        }
+        
+        native_shared_ptr<native::CqServiceStatistics>^ m_nativeptr;
       };
     }  // namespace Client
   }  // namespace Geode

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqState.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqState.cpp b/src/clicache/src/CqState.cpp
index 5f99fed..0a83a1d 100644
--- a/src/clicache/src/CqState.cpp
+++ b/src/clicache/src/CqState.cpp
@@ -32,59 +32,59 @@ namespace Apache
 
       String^ CqState::ToString()
       {
-                 return ManagedString::Get(NativePtr->toString());
+                 return ManagedString::Get(m_nativeptr->toString());
       }
 
       bool CqState::IsRunning()
       {
-        return NativePtr->isRunning();
+        return m_nativeptr->isRunning();
       }
 
       bool CqState::IsStopped()
       {
-        return NativePtr->isStopped();
+        return m_nativeptr->isStopped();
       }
 
       bool CqState::IsClosed()
       {
-       return NativePtr->isClosed();
+        return m_nativeptr->isClosed();
       }
 
       bool CqState::IsClosing()
       {
-       return NativePtr->isClosing();
+        return m_nativeptr->isClosing();
       }
 
       void CqState::SetState( CqStateType state )
       {
-                 apache::geode::client::CqState::StateType st 
=apache::geode::client::CqState::INVALID;
-                 if(state == CqStateType::STOPPED)
-                         st = apache::geode::client::CqState::STOPPED;
-                 else if(state == CqStateType::RUNNING)
-                         st = apache::geode::client::CqState::RUNNING;
-                 else if(state == CqStateType::CLOSED)
-                         st = apache::geode::client::CqState::CLOSED;
-                 else if(state == CqStateType::CLOSING)
-                         st = apache::geode::client::CqState::CLOSING;
-
-                 NativePtr->setState( st );
+             apache::geode::client::CqState::StateType st 
=apache::geode::client::CqState::INVALID;
+             if(state == CqStateType::STOPPED)
+                     st = apache::geode::client::CqState::STOPPED;
+             else if(state == CqStateType::RUNNING)
+                     st = apache::geode::client::CqState::RUNNING;
+             else if(state == CqStateType::CLOSED)
+                     st = apache::geode::client::CqState::CLOSED;
+             else if(state == CqStateType::CLOSING)
+                     st = apache::geode::client::CqState::CLOSING;
+      
+        m_nativeptr->setState( st );
       }
 
       CqStateType CqState::GetState( )
       {
-               apache::geode::client::CqState::StateType st =  
NativePtr->getState( );
-        CqStateType state;
-               if(st==apache::geode::client::CqState::STOPPED)
-                       state = CqStateType::STOPPED;
-               else if(st==apache::geode::client::CqState::RUNNING)
-                       state = CqStateType::RUNNING;
-               else if(st==apache::geode::client::CqState::CLOSED)
-                       state = CqStateType::CLOSED;
-               else if(st==apache::geode::client::CqState::CLOSING)
-                       state = CqStateType::CLOSING;
-               else
-                       state = CqStateType::INVALID;
-               return state;
+                   apache::geode::client::CqState::StateType st =  
m_nativeptr->getState( );
+            CqStateType state;
+                   if(st==apache::geode::client::CqState::STOPPED)
+                           state = CqStateType::STOPPED;
+                   else if(st==apache::geode::client::CqState::RUNNING)
+                           state = CqStateType::RUNNING;
+                   else if(st==apache::geode::client::CqState::CLOSED)
+                           state = CqStateType::CLOSED;
+                   else if(st==apache::geode::client::CqState::CLOSING)
+                           state = CqStateType::CLOSING;
+                   else
+                           state = CqStateType::INVALID;
+                   return state;
     }  // namespace Client
   }  // namespace Geode
 }  // namespace Apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqState.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqState.hpp b/src/clicache/src/CqState.hpp
index 52ab2bb..21ad5e6 100644
--- a/src/clicache/src/CqState.hpp
+++ b/src/clicache/src/CqState.hpp
@@ -18,8 +18,11 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/CqState.hpp>
-#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+
+
 
 using namespace System;
 
@@ -29,6 +32,7 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       /// <summary>
       /// Enumerated type for cq state
@@ -50,7 +54,6 @@ namespace Apache
       /// Static class containing convenience methods for <c>CqState</c>.
       /// </summary>
       public ref class CqState sealed
-        : public Internal::UMWrap<apache::geode::client::CqState>
       {
       public:
 
@@ -66,7 +69,7 @@ namespace Apache
 
         /// <summary>
         /// Returns true if the CQ is in Stopped state.
-       /// </summary>
+             /// </summary>
         bool IsStopped();
 
         /// <summary>
@@ -76,20 +79,24 @@ namespace Apache
 
         /// <summary>
         /// Returns true if the CQ is in Closing state.
-       /// </summary>
+             /// </summary>
         bool IsClosing();
-       void SetState(CqStateType state);
-       CqStateType GetState();
-
-        internal:
+             void SetState(CqStateType state);
+             CqStateType GetState();
+  
+      internal:
 
         /// <summary>
         /// Internal constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline CqState( apache::geode::client::CqState* nativeptr )
-                           : UMWrap( nativeptr, false ) { }
-
+        inline CqState( native::CqState* nativeptr )
+          : m_nativeptr(nativeptr)
+        {
+        }
+              
+      private:
+        native::CqState* m_nativeptr;
       };
     }  // namespace Client
   }  // namespace Geode

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqStatistics.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqStatistics.cpp 
b/src/clicache/src/CqStatistics.cpp
index 8378f20..ad19481 100644
--- a/src/clicache/src/CqStatistics.cpp
+++ b/src/clicache/src/CqStatistics.cpp
@@ -15,34 +15,62 @@
  * limitations under the License.
  */
 
-//#include "geode_includes.hpp"
 #include "CqStatistics.hpp"
 
-
 namespace Apache
 {
   namespace Geode
   {
     namespace Client
     {
+      using namespace System;
+
+      System::UInt32 CqStatistics::numInserts()
+      {
+        try
+        {
+          return m_nativeptr->get()->numInserts();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+      System::UInt32 CqStatistics::numDeletes()
+      {
+        try
+        {
+          return m_nativeptr->get()->numDeletes();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+      System::UInt32 CqStatistics::numUpdates()
+      {
+        try
+        {
+          return m_nativeptr->get()->numUpdates();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
+      System::UInt32 CqStatistics::numEvents()
+      {
+        try
+        {
+          return m_nativeptr->get()->numEvents();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+      }
 
-               System::UInt32 CqStatistics::numInserts( )
-       {
-         return NativePtr->numInserts( );
-       }
-    System::UInt32 CqStatistics::numDeletes( )
-       {
-         return NativePtr->numDeletes( );
-       }
-    System::UInt32 CqStatistics::numUpdates( )
-       {
-         return NativePtr->numUpdates( );
-       }
-    System::UInt32 CqStatistics::numEvents( )
-       {
-         return NativePtr->numEvents( );
     }  // namespace Client
   }  // namespace Geode
 }  // namespace Apache
 
- } //namespace 

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/CqStatistics.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/CqStatistics.hpp 
b/src/clicache/src/CqStatistics.hpp
index 69b6416..05aa23c 100644
--- a/src/clicache/src/CqStatistics.hpp
+++ b/src/clicache/src/CqStatistics.hpp
@@ -18,8 +18,10 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/CqStatistics.hpp>
-#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+#include "native_shared_ptr.hpp"
 
 
 namespace Apache
@@ -28,12 +30,12 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       /// <summary>
       /// Defines common statistical information for a cq.
       /// </summary>
       public ref class CqStatistics sealed
-        : public Internal::SBWrap<apache::geode::client::CqStatistics>
       {
       public:
 
@@ -67,13 +69,10 @@ namespace Apache
         /// <returns>
         /// The managed wrapper object; null if the native pointer is null.
         /// </returns>
-        inline static CqStatistics^ Create( 
apache::geode::client::CqStatistics* nativeptr )
+        inline static CqStatistics^ Create( 
apache::geode::client::CqStatisticsPtr nativeptr )
         {
-          if (nativeptr == nullptr)
-          {
-            return nullptr;
-          }
-          return gcnew CqStatistics( nativeptr );
+          return __nullptr == nativeptr ? nullptr :
+            gcnew CqStatistics( nativeptr );
         }
 
 
@@ -83,8 +82,13 @@ namespace Apache
         /// Private constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline CqStatistics( apache::geode::client::CqStatistics* nativeptr )
-          : SBWrap( nativeptr ) { }
+        inline CqStatistics( apache::geode::client::CqStatisticsPtr nativeptr )
+        {
+          m_nativeptr = gcnew 
native_shared_ptr<native::CqStatistics>(nativeptr);
+        }
+
+        native_shared_ptr<native::CqStatistics>^ m_nativeptr;
+
       };
     }  // namespace Client
   }  // namespace Geode

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/DataInput.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/DataInput.cpp b/src/clicache/src/DataInput.cpp
index ea32707..e6d7ac1 100644
--- a/src/clicache/src/DataInput.cpp
+++ b/src/clicache/src/DataInput.cpp
@@ -15,14 +15,15 @@
  * limitations under the License.
  */
 
-//#include "geode_includes.hpp"
-#include "DataInput.hpp"
+#include "begin_native.hpp"
 #include <geode/Cache.hpp>
-//#include "CacheFactory.hpp"
-#include "Cache.hpp"
-#include <vcclr.h>
-//#include <geode/GeodeTypeIds.hpp>
 #include <GeodeTypeIdsImpl.hpp>
+#include "end_native.hpp"
+
+#include <vcclr.h>
+
+#include "DataInput.hpp"
+#include "Cache.hpp"
 #include "CacheableString.hpp"
 #include "CacheableHashMap.hpp"
 #include "CacheableStack.hpp"
@@ -31,7 +32,6 @@
 #include "CacheableIDentityHashMap.hpp"
 #include "CacheableDate.hpp"
 #include "CacheableObjectArray.hpp"
-
 #include "Serializable.hpp"
 #include "impl/PdxHelper.hpp"
 
@@ -45,6 +45,7 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       DataInput::DataInput(System::Byte* buffer, int size)
       {
@@ -53,13 +54,20 @@ namespace Apache
         if (buffer != nullptr && size > 0) {
           _GF_MG_EXCEPTION_TRY2
 
-            SetPtr(new apache::geode::client::DataInput(buffer, size), true);
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataInput>(std::make_unique<native::DataInput>(buffer,
 size));
           m_cursor = 0;
           m_isManagedObject = false;
           m_forStringDecode = gcnew array<Char>(100);
 
-          m_buffer = 
const_cast<System::Byte*>(NativePtr->currentBufferPosition());
-          m_bufferLength = NativePtr->getBytesRemaining();
+          try
+          {
+            m_buffer = 
const_cast<System::Byte*>(m_nativeptr->get()->currentBufferPosition());
+            m_bufferLength = m_nativeptr->get()->getBytesRemaining();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
           _GF_MG_EXCEPTION_CATCH_ALL2
         }
@@ -80,14 +88,21 @@ namespace Apache
           GF_NEW(m_buffer, System::Byte[len]);
           pin_ptr<const Byte> pin_buffer = &buffer[0];
           memcpy(m_buffer, (void*)pin_buffer, len);
-          SetPtr(new apache::geode::client::DataInput(m_buffer, len), true);
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataInput>(std::unique_ptr<native::DataInput>(new
 native::DataInput(m_buffer, len)));
 
           m_cursor = 0;
           m_isManagedObject = false;
           m_forStringDecode = gcnew array<Char>(100);
 
-          m_buffer = 
const_cast<System::Byte*>(NativePtr->currentBufferPosition());
-          m_bufferLength = NativePtr->getBytesRemaining();
+          try
+          {
+            m_buffer = 
const_cast<System::Byte*>(m_nativeptr->get()->currentBufferPosition());
+            m_bufferLength = m_nativeptr->get()->getBytesRemaining();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
           _GF_MG_EXCEPTION_CATCH_ALL2
         }
@@ -114,10 +129,17 @@ namespace Apache
             GF_NEW(m_buffer, System::Byte[len]);
           pin_ptr<const Byte> pin_buffer = &buffer[0];
           memcpy(m_buffer, (void*)pin_buffer, len);
-          SetPtr(new apache::geode::client::DataInput(m_buffer, len), true);
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataInput>(std::unique_ptr<native::DataInput>(new
 native::DataInput(m_buffer, len)));
 
-          m_buffer = 
const_cast<System::Byte*>(NativePtr->currentBufferPosition());
-          m_bufferLength = NativePtr->getBytesRemaining();
+          try
+          {
+            m_buffer = 
const_cast<System::Byte*>(m_nativeptr->get()->currentBufferPosition());
+            m_bufferLength = m_nativeptr->get()->getBytesRemaining();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
           _GF_MG_EXCEPTION_CATCH_ALL2
         }
@@ -619,6 +641,8 @@ namespace Apache
 
       Object^ DataInput::ReadInternalObject()
       {
+        try
+        {
         //Log::Debug("DataInput::ReadInternalObject m_cursor " + m_cursor);
         bool findinternal = false;
         int8_t typeId = ReadByte();
@@ -635,11 +659,11 @@ namespace Apache
           System::Byte* cacheBuffer = m_buffer;
           unsigned int cacheBufferLength = m_bufferLength;
           Object^ ret = Internal::PdxHelper::DeserializePdx(this, false);
-          int tmp = NativePtr->getBytesRemaining();
+          int tmp = m_nativeptr->get()->getBytesRemaining();
           m_cursor = cacheBufferLength - tmp;
           m_buffer = cacheBuffer;
           m_bufferLength = cacheBufferLength;
-          NativePtr->rewindCursor(m_cursor);
+          m_nativeptr->get()->rewindCursor(m_cursor);
 
           if (ret != nullptr)
           {
@@ -735,6 +759,11 @@ namespace Apache
         newObj->FromData(this);
         m_ispdxDesrialization = isPdxDeserialization;
         return newObj;
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       Object^ DataInput::readDotNetObjectArray()
@@ -850,7 +879,14 @@ namespace Apache
         AdvanceUMCursor();
         SetBuffer();
 
-        return NativePtr->getBytesRead();
+        try
+        {
+          return m_nativeptr->get()->getBytesRead();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       System::UInt32 DataInput::BytesReadInternally::get()
@@ -862,8 +898,14 @@ namespace Apache
       {
         AdvanceUMCursor();
         SetBuffer();
-        return NativePtr->getBytesRemaining();
-        //return m_bufferLength - m_cursor;
+        try
+        {
+          return m_nativeptr->get()->getBytesRemaining();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       void DataInput::AdvanceCursor(System::Int32 offset)
@@ -874,24 +916,35 @@ namespace Apache
       void DataInput::RewindCursor(System::Int32 offset)
       {
         AdvanceUMCursor();
-        NativePtr->rewindCursor(offset);
+        try
+        {
+          m_nativeptr->get()->rewindCursor(offset);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         SetBuffer();
-        //m_cursor -= offset;
       }
 
       void DataInput::Reset()
       {
         AdvanceUMCursor();
-        NativePtr->reset();
+        try
+        {
+          m_nativeptr->get()->reset();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         SetBuffer();
-        //  m_cursor = 0;
       }
 
       void DataInput::Cleanup()
       {
         //TODO:
         //GF_SAFE_DELETE_ARRAY(m_buffer);
-        InternalCleanup();
       }
 
       void DataInput::ReadDictionary(System::Collections::IDictionary^ dict)

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/DataInput.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/DataInput.hpp b/src/clicache/src/DataInput.hpp
index 35bc6b5..8797381 100644
--- a/src/clicache/src/DataInput.hpp
+++ b/src/clicache/src/DataInput.hpp
@@ -18,12 +18,13 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/DataInput.hpp>
-#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+
+#include "native_conditional_unique_ptr.hpp"
 #include "Log.hpp"
 #include "ExceptionTypes.hpp"
-//#include "../../CacheableDate.hpp"
-
 
 using namespace System;
 using namespace System::Collections::Generic;
@@ -35,6 +36,8 @@ namespace Apache
     namespace Client
     {
 
+      namespace native = apache::geode::client;
+
       interface class IGeodeSerializable;
 
       /// <summary>
@@ -42,7 +45,6 @@ namespace Apache
       /// strings, <c>IGeodeSerializable</c> objects from a byte stream.
       /// </summary>
       public ref class DataInput sealed
-                               : public 
Client::Internal::UMWrap<apache::geode::client::DataInput>
       {
       public:
 
@@ -211,17 +213,6 @@ namespace Apache
         /// Reset the cursor to the start of buffer.
         /// </summary>
         void Reset();
-
-        /// <summary>
-        /// Get the underlying native unmanaged pointer.
-        /// </summary>
-        property IntPtr NativeIntPtr
-        {
-          inline IntPtr get()
-          {
-            return IntPtr(_NativePtr);
-          }
-        }
         
         /// <summary>
         /// Read a dictionary from the stream in a given dictionary instance.
@@ -287,6 +278,11 @@ namespace Apache
 
       internal:
 
+        native::DataInput* GetNative()
+        {
+          return m_nativeptr->get();
+        }
+
         void setPdxdeserialization(bool val)
         {
           m_ispdxDesrialization = true;
@@ -307,7 +303,13 @@ namespace Apache
 
         const char * GetPoolName()
         {
-          return _NativePtr->getPoolName();
+          try
+          {
+            return m_nativeptr->get()->getPoolName();
+          }
+          finally {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
 
         Object^ ReadDotNetTypes(int8_t typeId);
@@ -504,13 +506,26 @@ namespace Apache
 
         System::Byte* GetBytes(System::Byte* src, System::UInt32 size)
         {
-          return NativePtr->getBufferCopyFrom(src, size);
+          try
+          {
+            return m_nativeptr->get()->getBufferCopyFrom(src, size);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
 
         
         void AdvanceUMCursor()
         {
-                                       NativePtr->advanceCursor(m_cursor);
+          try {
+            m_nativeptr->get()->advanceCursor(m_cursor);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
           m_cursor = 0;
           m_bufferLength = 0;
         }
@@ -532,7 +547,14 @@ namespace Apache
 
         void ResetPdx(int offset)
         {
-          NativePtr->reset(offset);
+          try
+          {
+            m_nativeptr->get()->reset(offset);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
           SetBuffer();
         }
 
@@ -540,9 +562,16 @@ namespace Apache
 
         void SetBuffer()
         {
-          m_buffer = const_cast<System::Byte*> 
(NativePtr->currentBufferPosition());
-          m_cursor = 0;
-          m_bufferLength = NativePtr->getBytesRemaining();   
+          try
+          {
+            m_buffer = const_cast<System::Byte*> 
(m_nativeptr->get()->currentBufferPosition());
+            m_cursor = 0;
+            m_bufferLength = m_nativeptr->get()->getBytesRemaining();   
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
 
         String^ DecodeBytes(int length)
@@ -628,8 +657,8 @@ namespace Apache
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
         inline DataInput( apache::geode::client::DataInput* nativeptr, bool 
managedObject )
-          : UMWrap(nativeptr, false)
         { 
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataInput>(nativeptr);
           m_ispdxDesrialization = false;
           m_isRootObjectPdx = false;
           m_cursor = 0;
@@ -646,20 +675,6 @@ namespace Apache
 
         DataInput( System::Byte* buffer, int size );
 
-       /* inline DataInput( apache::geode::client::DataInput* nativeptr )
-          : UMWrap(nativeptr, false)
-        { 
-          m_cursor = 0;
-          m_isManagedObject = false;
-          m_buffer = 
const_cast<System::Byte*>(nativeptr->currentBufferPosition());
-          if ( m_buffer != NULL) {
-            m_bufferLength = nativeptr->getBytesRemaining();            
-          }
-          else {
-            m_bufferLength = 0;
-          }
-        }*/
-
         bool IsManagedObject()
         {
           return m_isManagedObject;
@@ -683,6 +698,8 @@ namespace Apache
         int m_cursor;
         bool m_isManagedObject;
         array<Char>^ m_forStringDecode;
+
+        native_conditional_unique_ptr<native::DataInput>^ m_nativeptr;
       
         void Cleanup( );
       };

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/DataOutput.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/DataOutput.cpp b/src/clicache/src/DataOutput.cpp
index 3ea133d..8ced074 100644
--- a/src/clicache/src/DataOutput.cpp
+++ b/src/clicache/src/DataOutput.cpp
@@ -15,15 +15,18 @@
  * limitations under the License.
  */
 
-//#include "geode_includes.hpp"
-#include "DataOutput.hpp"
+#include "begin_native.hpp"
 #include <GeodeTypeIdsImpl.hpp>
+#include "end_native.hpp"
+
 #include <vcclr.h>
 
+#include "DataOutput.hpp"
 #include "IGeodeSerializable.hpp"
 #include "CacheableObjectArray.hpp"
 #include "impl/PdxHelper.hpp"
 #include "impl/PdxWrapper.hpp"
+
 using namespace System;
 using namespace System::Runtime::InteropServices;
 using namespace apache::geode::client;
@@ -731,23 +734,36 @@ namespace Apache
       {
         //first set native one
         WriteBytesToUMDataOutput();
-        NativePtr->rewindCursor(offset);
+        try
+        {
+          m_nativeptr->get()->rewindCursor(offset);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         SetBuffer();
       }
 
       array<Byte>^ DataOutput::GetBuffer()
       {
-        WriteBytesToUMDataOutput();
-        SetBuffer();
-
-        int buffLen = NativePtr->getBufferLength();
-        array<Byte>^ buffer = gcnew array<Byte>(buffLen);
+        try
+        {
+          WriteBytesToUMDataOutput();
+          SetBuffer();
+          int buffLen = m_nativeptr->get()->getBufferLength();
+          array<Byte>^ buffer = gcnew array<Byte>(buffLen);
 
-        if (buffLen > 0) {
-          pin_ptr<Byte> pin_buffer = &buffer[0];
-          memcpy((void*)pin_buffer, NativePtr->getBuffer(), buffLen);
+          if (buffLen > 0) {
+            pin_ptr<Byte> pin_buffer = &buffer[0];
+            memcpy((void*)pin_buffer, m_nativeptr->get()->getBuffer(), 
buffLen);
+          }
+          return buffer;
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
         }
-        return buffer;
       }
 
       System::UInt32 DataOutput::BufferLength::get()
@@ -756,13 +772,27 @@ namespace Apache
         WriteBytesToUMDataOutput();
         SetBuffer();
 
-        return NativePtr->getBufferLength();
+        try
+        {
+          return m_nativeptr->get()->getBufferLength();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       void DataOutput::Reset()
       {
         WriteBytesToUMDataOutput();
-        NativePtr->reset();
+        try
+        {
+          m_nativeptr->get()->reset();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         SetBuffer();
       }
 
@@ -784,7 +814,14 @@ namespace Apache
 
       void DataOutput::WriteBytesToUMDataOutput()
       {
-        NativePtr->advanceCursor(m_cursor);
+        try
+        {
+          m_nativeptr->get()->advanceCursor(m_cursor);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         m_cursor = 0;
         m_remainingBufferLength = 0;
         m_bytes = nullptr;
@@ -876,8 +913,7 @@ namespace Apache
       void DataOutput::WriteDoubleArray(array<double>^ doubleArray)
       {
         WriteObject<double>(doubleArray);
-      }  // namespace Client
-    }  // namespace Geode
-  }  // namespace Apache
-
-}
+      }
+    }  // namespace Client
+  }  // namespace Geode
+}  // namespace Apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/DataOutput.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/DataOutput.hpp b/src/clicache/src/DataOutput.hpp
index f57179f..81e610d 100644
--- a/src/clicache/src/DataOutput.hpp
+++ b/src/clicache/src/DataOutput.hpp
@@ -18,8 +18,11 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/DataOutput.hpp>
-//#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+
+#include "native_conditional_unique_ptr.hpp"
 #include "Log.hpp"
 #include "ExceptionTypes.hpp"
 #include "Serializable.hpp"
@@ -39,6 +42,7 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       interface class IGeodeSerializable;
 
@@ -48,7 +52,6 @@ namespace Apache
       /// This class is intentionally not thread safe.
       /// </summary>
       public ref class DataOutput sealed
-                               : public 
Client::Internal::UMWrap<apache::geode::client::DataOutput>
       {
       private:
         System::Int32 m_cursor;
@@ -56,18 +59,27 @@ namespace Apache
         System::Byte * m_bytes;
         System::Int32 m_remainingBufferLength;
         bool m_ispdxSerialization;
+        native_conditional_unique_ptr<native::DataOutput>^ m_nativeptr;
+
       public:
 
         /// <summary>
         /// Default constructor.
         /// </summary>
         inline DataOutput( )
-          : UMWrap( new apache::geode::client::DataOutput( ), true )
         { 
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataOutput>(std::make_unique<native::DataOutput>());
           m_isManagedObject = true;
           m_cursor = 0;
-          m_bytes = const_cast<System::Byte *>(NativePtr->getCursor());
-          m_remainingBufferLength = 
(System::Int32)NativePtr->getRemainingBufferLength();
+          try
+          {
+            m_bytes = const_cast<System::Byte 
*>(m_nativeptr->get()->getCursor());
+            m_remainingBufferLength = 
(System::Int32)m_nativeptr->get()->getRemainingBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
           m_ispdxSerialization = false;
         }
 
@@ -278,17 +290,6 @@ namespace Apache
         /// Reset the cursor to the start of the buffer.
         /// </summary>
         void Reset( );
-
-        /// <summary>
-        /// Get the underlying native unmanaged pointer.
-        /// </summary>
-        property IntPtr NativeIntPtr
-        {
-          inline IntPtr get()
-          {
-            return IntPtr(_NativePtr);
-          }
-        }
        
         /// <summary>
         /// Write a Dictionary to the DataOutput.
@@ -364,6 +365,11 @@ namespace Apache
                
       internal:
 
+        native::DataOutput* GetNative()
+        {
+          return m_nativeptr->get();
+        }
+
         void WriteDotNetObjectArray(Object^ objectArray);
 
         /// <summary>
@@ -393,7 +399,14 @@ namespace Apache
 
                          System::Int32 GetBufferLengthPdx()
         {
-          return (System::Int32)NativePtr->getBufferLength();
+          try
+          {
+            return (System::Int32)m_nativeptr->get()->getBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
 
         void WriteString(String^ value);
@@ -405,7 +418,14 @@ namespace Apache
 
         const char * GetPoolName()
         {
-          return _NativePtr->getPoolName();
+          try
+          {
+            return m_nativeptr->get()->getPoolName();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
 
         void WriteStringArray(array<String^>^ strArray);
@@ -543,13 +563,27 @@ namespace Apache
         void SetBuffer()
         {
           m_cursor = 0;
-          m_bytes = const_cast<System::Byte *>(NativePtr->getCursor());
-          m_remainingBufferLength = 
(System::Int32)NativePtr->getRemainingBufferLength();
+          try
+          {
+            m_bytes = const_cast<System::Byte 
*>(m_nativeptr->get()->getCursor());
+            m_remainingBufferLength = 
(System::Int32)m_nativeptr->get()->getRemainingBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
 
                                System::Byte* GetStartBufferPosition()
         {
-          return const_cast<System::Byte *>( NativePtr->getBuffer());;
+          try
+          {
+            return const_cast<System::Byte *>( 
m_nativeptr->get()->getBuffer());
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          };
         }
 
         inline void EnsureCapacity( System::Int32 size )
@@ -558,14 +592,19 @@ namespace Apache
           if ( bytesLeft < size ) {
             try
             {
-              NativePtr->ensureCapacity(m_cursor + size);
-              m_bytes = const_cast<System::Byte *>( NativePtr->getCursor());
-              m_remainingBufferLength = 
(System::Int32)NativePtr->getRemainingBufferLength();
+              auto p = m_nativeptr->get();
+              p->ensureCapacity(m_cursor + size);
+              m_bytes = const_cast<System::Byte *>( p->getCursor());
+              m_remainingBufferLength = 
(System::Int32)p->getRemainingBufferLength();
             }
             catch(apache::geode::client::OutOfMemoryException ex )
             {
               throw gcnew OutOfMemoryException(ex);
             }            
+            finally
+            {
+              GC::KeepAlive(m_nativeptr);
+            }
           }
         }
 
@@ -579,12 +618,26 @@ namespace Apache
 
         System::Byte* GetBytes(System::Byte* src, System::UInt32 size)
         {
-          return NativePtr->getBufferCopyFrom(src, size);
+          try
+          {
+            return m_nativeptr->get()->getBufferCopyFrom(src, size);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
  
         System::Int32 GetRemainingBufferLength()
         {
-          return (System::Int32) NativePtr->getRemainingBufferLength();
+          try
+          {
+            return (System::Int32) 
m_nativeptr->get()->getRemainingBufferLength();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
 
         /// <summary>
@@ -592,8 +645,8 @@ namespace Apache
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
         inline DataOutput( apache::geode::client::DataOutput* nativeptr, bool 
managedObject )
-          : UMWrap( nativeptr, false )
         {
+          m_nativeptr = gcnew 
native_conditional_unique_ptr<native::DataOutput>(nativeptr);
           m_isManagedObject = managedObject;
           m_cursor = 0;
           m_bytes = const_cast<System::Byte *>(nativeptr->getCursor());

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/DiskPolicyType.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/DiskPolicyType.hpp 
b/src/clicache/src/DiskPolicyType.hpp
index 03d66d8..e9d3953 100644
--- a/src/clicache/src/DiskPolicyType.hpp
+++ b/src/clicache/src/DiskPolicyType.hpp
@@ -20,7 +20,10 @@
 
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/DiskPolicyType.hpp>
+#include "end_native.hpp"
+
 
 
 using namespace System;

Reply via email to