geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbarr...@apache.org
Subject [35/46] geode-native git commit: GEODE-2741: Remove custom shared pointer from clicache
Date Wed, 17 May 2017 17:50:17 GMT
http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/Region.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/Region.cpp b/src/clicache/src/Region.cpp
index 6100412..0ea7aa2 100644
--- a/src/clicache/src/Region.cpp
+++ b/src/clicache/src/Region.cpp
@@ -15,7 +15,6 @@
  * limitations under the License.
  */
 
-//#include "geode_includes.hpp"
 #include "Region.hpp"
 #include "Cache.hpp"
 #include "CacheStatistics.hpp"
@@ -28,15 +27,11 @@
 #include "StructSet.hpp"
 #include "impl/AuthenticatedCache.hpp"
 #include "impl/SafeConvert.hpp"
-//#include <geode/Serializable.hpp>
-//#include <cppcache/DataOutPut.hpp>
 #include "LocalRegion.hpp"
 #include "Pool.hpp"
 #include "PoolManager.hpp"
 #include "SystemProperties.hpp"
 
-using namespace System;
-
 namespace Apache
 {
   namespace Geode
@@ -44,35 +39,50 @@ namespace Apache
     namespace Client
     {
 
+      using namespace System;
+      namespace native = apache::geode::client;
+
       generic<class TKey, class TValue>
       TValue Region<TKey, TValue>::Get(TKey key, Object^ callbackArg)
       {
-        apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        apache::geode::client::CacheablePtr nativeptr(this->get(keyptr, callbackptr));
+        native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+        native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+        auto nativeptr = this->get(keyptr, callbackptr);
         if (nativeptr == nullptr)
         {
           throw gcnew KeyNotFoundException("The given key was not present in the region.");
         }
         TValue returnVal = Serializable::GetManagedValueGeneric<TValue>(nativeptr);
         return returnVal;
-
       }
 
       generic<class TKey, class TValue>
-      apache::geode::client::SerializablePtr Region<TKey, TValue>::get(apache::geode::client::CacheableKeyPtr& keyptr, apache::geode::client::SerializablePtr& callbackptr)
+      native::SerializablePtr Region<TKey, TValue>::get(native::CacheableKeyPtr& keyptr, native::SerializablePtr& callbackptr)
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-          return NativePtr->get(keyptr, callbackptr);
+          try
+          {
+            return m_nativeptr->get()->get(keyptr, callbackptr);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
       generic<class TKey, class TValue>
-      apache::geode::client::SerializablePtr Region<TKey, TValue>::get(apache::geode::client::CacheableKeyPtr& keyptr)
+      native::SerializablePtr Region<TKey, TValue>::get(native::CacheableKeyPtr& keyptr)
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-          return NativePtr->get(keyptr);
+          try
+          {
+            return m_nativeptr->get()->get(keyptr);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
@@ -80,15 +90,15 @@ namespace Apache
       bool Region<TKey, TValue>::isPoolInMultiuserMode()
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-          Apache::Geode::Client::RegionAttributes<TKey, TValue>^ rAttributes = this->Attributes;
-        String^ poolName = rAttributes->PoolName;
-        if (poolName != nullptr) {
-          Pool/*<TKey, TValue>*/^ pool = PoolManager/*<TKey, TValue>*/::Find(poolName);
-          if (pool != nullptr && !pool->Destroyed) {
-            return pool->MultiuserAuthentication;
+          auto rAttributes = this->Attributes;
+          auto poolName = rAttributes->PoolName;
+          if (poolName != nullptr) {
+            auto pool = PoolManager::Find(poolName);
+            if (pool != nullptr && !pool->Destroyed) {
+              return pool->MultiuserAuthentication;
+            }
           }
-        }
-        return false;
+          return false;
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
@@ -97,20 +107,26 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(value));
-        apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        NativePtr->put(keyptr, valueptr, callbackptr);
-
+          try
+          {
+            native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+            native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(value);
+            native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+            m_nativeptr->get()->put(keyptr, valueptr, callbackptr);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+        
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
       generic<class TKey, class TValue>
       TValue Region<TKey, TValue>::default::get(TKey key)
       {
-        apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::CacheablePtr nativeptr(this->get(keyptr));
+        native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+        auto nativeptr = this->get(keyptr);
         if (nativeptr == nullptr)
         {
           throw gcnew KeyNotFoundException("The given key was not present in the region.");
@@ -124,9 +140,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(value));
-        NativePtr->put(keyptr, valueptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(value);
+          m_nativeptr->get()->put(keyptr, valueptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -135,22 +158,28 @@ namespace Apache
       System::Collections::Generic::IEnumerator<KeyValuePair<TKey, TValue>>^
         Region<TKey, TValue>::GetEnumerator()
       {
-        array<KeyValuePair<TKey, TValue>>^ toArray;
-        apache::geode::client::VectorOfRegionEntry vc;
+        native::VectorOfRegionEntry vc;
 
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          NativePtr->entries(vc, false);
+          try
+          {
+            m_nativeptr->get()->entries(vc, false);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
-          toArray = gcnew array<KeyValuePair<TKey, TValue>>(vc.size());
+          auto toArray = gcnew array<KeyValuePair<TKey, TValue>>(vc.size());
 
         for (System::Int32 index = 0; index < vc.size(); index++)
         {
-          apache::geode::client::RegionEntryPtr nativeptr = vc[index];
-          TKey key = Serializable::GetManagedValueGeneric<TKey>(nativeptr->getKey());
-          TValue val = Serializable::GetManagedValueGeneric<TValue>(nativeptr->getValue());
+          auto& nativeptr = vc[index];
+          auto key = Serializable::GetManagedValueGeneric<TKey>(nativeptr->getKey());
+          auto val = Serializable::GetManagedValueGeneric<TValue>(nativeptr->getValue());
           toArray[index] = KeyValuePair<TKey, TValue>(key, val);
         }
         return ((System::Collections::Generic::IEnumerable<KeyValuePair<TKey, TValue>>^)toArray)->GetEnumerator();
@@ -160,29 +189,35 @@ namespace Apache
       System::Collections::IEnumerator^
         Region<TKey, TValue>::GetEnumeratorOld()
       {
-        array<Object^>^ toArray;
-        apache::geode::client::VectorOfRegionEntry vc;
+        native::VectorOfRegionEntry vc;
 
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          NativePtr->entries(vc, false);
+          try
+          {
+            m_nativeptr->get()->entries(vc, false);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
-          toArray = gcnew array<Object^>(vc.size());
+         auto toArray = gcnew array<Object^>(vc.size());
 
         for (System::Int32 index = 0; index < vc.size(); index++)
         {
-          apache::geode::client::RegionEntryPtr nativeptr = vc[index];
-          TKey key = Serializable::GetManagedValueGeneric<TKey>(nativeptr->getKey());
-          TValue val = Serializable::GetManagedValueGeneric<TValue>(nativeptr->getValue());
+          auto& nativeptr = vc[index];
+          auto key = Serializable::GetManagedValueGeneric<TKey>(nativeptr->getKey());
+          auto val = Serializable::GetManagedValueGeneric<TValue>(nativeptr->getValue());
           toArray[index] = KeyValuePair<TKey, TValue>(key, val);
         }
         return ((System::Collections::Generic::IEnumerable<Object^>^)toArray)->GetEnumerator();
       }
 
       generic<class TKey, class TValue>
-      bool Region<TKey, TValue>::AreValuesEqual(apache::geode::client::CacheablePtr& val1, apache::geode::client::CacheablePtr& val2)
+      bool Region<TKey, TValue>::AreValuesEqual(native::CacheablePtr& val1, native::CacheablePtr& val2)
       {
         if (val1 == nullptr && val2 == nullptr)
         {
@@ -198,8 +233,8 @@ namespace Apache
           {
             return false;
           }
-          apache::geode::client::DataOutput out1;
-          apache::geode::client::DataOutput out2;
+          native::DataOutput out1;
+          native::DataOutput out2;
           val1->toData(out1);
           val2->toData(out2);
           if (out1.getBufferLength() != out2.getBufferLength())
@@ -218,13 +253,13 @@ namespace Apache
       generic<class TKey, class TValue>
       bool Region<TKey, TValue>::Contains(KeyValuePair<TKey, TValue> keyValuePair)
       {
-        apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(keyValuePair.Key));
-        apache::geode::client::CacheablePtr nativeptr(this->get(keyptr));
+        native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(keyValuePair.Key);
+        auto nativeptr = this->get(keyptr);
         //This means that key is not present.
         if (nativeptr == nullptr) {
           return false;
         }
-        TValue value = Serializable::GetManagedValueGeneric<TValue>(nativeptr);
+        auto value = Serializable::GetManagedValueGeneric<TValue>(nativeptr);
         return ((Object^)value)->Equals(keyValuePair.Value);
       }
 
@@ -233,9 +268,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-
-        return NativePtr->containsKeyOnServer(keyptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          return m_nativeptr->get()->containsKeyOnServer(keyptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -244,8 +285,8 @@ namespace Apache
       bool Region<TKey, TValue>::TryGetValue(TKey key, TValue %val)
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::CacheablePtr nativeptr(this->get(keyptr));
+        native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+        auto nativeptr = this->get(keyptr);
         if (nativeptr == nullptr) {
           val = TValue();
           return false;
@@ -263,19 +304,22 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfCacheableKey vc;
-        NativePtr->serverKeys(vc);
-        //List<TKey>^ collectionlist = gcnew List<TKey>(vc.size());
-        array<TKey>^ keyarr =
-          gcnew array<TKey>(vc.size());
+          native::VectorOfCacheableKey vc;
+        try
+        {
+          m_nativeptr->get()->serverKeys(vc);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+        auto keyarr = gcnew array<TKey>(vc.size());
         for (System::Int32 index = 0; index < vc.size(); index++)
         {
-          apache::geode::client::CacheableKeyPtr& nativeptr(vc[index]);
+          auto& nativeptr = vc[index];
           keyarr[index] = Serializable::GetManagedValueGeneric<TKey>(nativeptr);
-          //collectionlist[ index ] = Serializable::GetManagedValue<TKey>(nativeptr);
         }
-        System::Collections::Generic::ICollection<TKey>^ collectionlist =
-          (System::Collections::Generic::ICollection<TKey>^)keyarr;
+        auto collectionlist = (System::Collections::Generic::ICollection<TKey>^)keyarr;
         return collectionlist;
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
@@ -286,19 +330,22 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfCacheable vc;
-        NativePtr->values(vc);
-        //List<TValue>^ collectionlist = gcnew List<TValue>(vc.size());
-        array<TValue>^ valarr =
-          gcnew array<TValue>(vc.size());
+          native::VectorOfCacheable vc;
+        try
+        {
+          m_nativeptr->get()->values(vc);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+        auto valarr = gcnew array<TValue>(vc.size());
         for (System::Int32 index = 0; index < vc.size(); index++)
         {
-          apache::geode::client::CacheablePtr& nativeptr(vc[index]);
+          auto& nativeptr = vc[index];
           valarr[index] = Serializable::GetManagedValueGeneric<TValue>(nativeptr);
-          //collectionlist[ index ] = Serializable::GetManagedValueGeneric<TValue>(nativeptr);
         }
-        System::Collections::Generic::ICollection<TValue>^ collectionlist =
-          (System::Collections::Generic::ICollection<TValue>^)valarr;
+        auto collectionlist = (System::Collections::Generic::ICollection<TValue>^)valarr;
         return collectionlist;
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
@@ -309,9 +356,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(value));
-        NativePtr->create(keyptr, valueptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(value);
+          m_nativeptr->get()->create(keyptr, valueptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -321,9 +375,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(keyValuePair.Key));
-        apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(keyValuePair.Value));
-        NativePtr->create(keyptr, valueptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(keyValuePair.Key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(keyValuePair.Value);
+          m_nativeptr->get()->create(keyptr, valueptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -333,11 +394,17 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(value));
-        apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        NativePtr->create(keyptr, valueptr, callbackptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(value);
+          native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+          m_nativeptr->get()->create(keyptr, valueptr, callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -347,8 +414,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        return NativePtr->removeEx(keyptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          return m_nativeptr->get()->removeEx(keyptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -359,10 +433,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        return NativePtr->removeEx(keyptr, callbackptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+          return m_nativeptr->get()->removeEx(keyptr, callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -372,10 +452,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(keyValuePair.Key));
-        apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(keyValuePair.Value));
-
-        return NativePtr->remove(keyptr, valueptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(keyValuePair.Key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(keyValuePair.Value);
+          return m_nativeptr->get()->remove(keyptr, valueptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -385,10 +471,17 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(value));
-        apache::geode::client::UserDataPtr callbackptr(Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        return NativePtr->remove(keyptr, valueptr, callbackptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(value);
+          native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+          return m_nativeptr->get()->remove(keyptr, valueptr, callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -408,9 +501,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        NativePtr->invalidateRegion(callbackptr);
+        try
+        {
+          native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+          m_nativeptr->get()->invalidateRegion(callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -430,9 +529,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        NativePtr->destroyRegion(callbackptr);
+        try
+        {
+          native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+          m_nativeptr->get()->destroyRegion(callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -453,10 +558,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        NativePtr->invalidate(keyptr, callbackptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+          m_nativeptr->get()->invalidate(keyptr, callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -477,14 +588,21 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::HashMapOfCacheable nativeMap;
+          native::HashMapOfCacheable nativeMap;
         for each (KeyValuePair<TKey, TValue> keyValPair in map)
         {
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(keyValPair.Key));
-          apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(keyValPair.Value));
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(keyValPair.Key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(keyValPair.Value);
           nativeMap.insert(keyptr, valueptr);
         }
-        NativePtr->putAll(nativeMap, timeout);
+        try
+        {
+          m_nativeptr->get()->putAll(nativeMap, timeout);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -495,16 +613,22 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::HashMapOfCacheable nativeMap;
+          native::HashMapOfCacheable nativeMap;
         for each (KeyValuePair<TKey, TValue> keyValPair in map)
         {
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(keyValPair.Key));
-          apache::geode::client::CacheablePtr valueptr(Serializable::GetUnmanagedValueGeneric<TValue>(keyValPair.Value));
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(keyValPair.Key);
+          native::CacheablePtr valueptr = Serializable::GetUnmanagedValueGeneric<TValue>(keyValPair.Value);
           nativeMap.insert(keyptr, valueptr);
         }
-        apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        NativePtr->putAll(nativeMap, timeout, callbackptr);
+        native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+        try
+        {
+          m_nativeptr->get()->putAll(nativeMap, timeout, callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -532,7 +656,7 @@ namespace Apache
         if (keys != nullptr) {
           _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-            apache::geode::client::VectorOfCacheableKey vecKeys;
+            native::VectorOfCacheableKey vecKeys;
 
           for each(TKey item in keys)
           {
@@ -540,18 +664,24 @@ namespace Apache
               Serializable::GetUnmanagedValueGeneric<TKey>(item));
           }
 
-          apache::geode::client::HashMapOfCacheablePtr valuesPtr(nullptr);
+          native::HashMapOfCacheablePtr valuesPtr;
           if (values != nullptr) {
-            valuesPtr = new apache::geode::client::HashMapOfCacheable();
+            valuesPtr = std::make_shared<native::HashMapOfCacheable>();
           }
-          apache::geode::client::HashMapOfExceptionPtr exceptionsPtr(nullptr);
+          native::HashMapOfExceptionPtr exceptionsPtr;
           if (exceptions != nullptr) {
-            exceptionsPtr = new apache::geode::client::HashMapOfException();
+            exceptionsPtr = std::make_shared<native::HashMapOfException>();
+          }
+          try
+          {
+            m_nativeptr->get()->getAll(vecKeys, valuesPtr, exceptionsPtr, addToLocalCache);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
           }
-          NativePtr->getAll(vecKeys, valuesPtr, exceptionsPtr,
-                            addToLocalCache);
           if (values != nullptr) {
-            for (apache::geode::client::HashMapOfCacheable::Iterator iter =
+            for (native::HashMapOfCacheable::Iterator iter =
                   valuesPtr->begin(); iter != valuesPtr->end(); ++iter) {
               TKey key = Serializable::GetManagedValueGeneric<TKey>(iter.first());
               TValue val = Serializable::GetManagedValueGeneric<TValue>(iter.second());
@@ -559,7 +689,7 @@ namespace Apache
             }
           }
           if (exceptions != nullptr) {
-            for (apache::geode::client::HashMapOfException::Iterator iter =
+            for (native::HashMapOfException::Iterator iter =
                   exceptionsPtr->begin(); iter != exceptionsPtr->end(); ++iter) {
               TKey key = Serializable::GetManagedValueGeneric<TKey>(iter.first());
               System::Exception^ ex = GeodeException::Get(*iter.second());
@@ -583,7 +713,7 @@ namespace Apache
         if (keys != nullptr) {
           _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-            apache::geode::client::VectorOfCacheableKey vecKeys;
+            native::VectorOfCacheableKey vecKeys;
 
           for each(TKey item in keys)
           {
@@ -591,22 +721,27 @@ namespace Apache
               Serializable::GetUnmanagedValueGeneric<TKey>(item));
           }
 
-          apache::geode::client::HashMapOfCacheablePtr valuesPtr(nullptr);
+          native::HashMapOfCacheablePtr valuesPtr;
           if (values != nullptr) {
-            valuesPtr = new apache::geode::client::HashMapOfCacheable();
+            valuesPtr = std::make_shared<native::HashMapOfCacheable>();
           }
-          apache::geode::client::HashMapOfExceptionPtr exceptionsPtr(nullptr);
+          native::HashMapOfExceptionPtr exceptionsPtr;
           if (exceptions != nullptr) {
-            exceptionsPtr = new apache::geode::client::HashMapOfException();
+            exceptionsPtr = std::make_shared<native::HashMapOfException>();
           }
 
-          apache::geode::client::UserDataPtr callbackptr(
-            Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
+         native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
 
-          NativePtr->getAll(vecKeys, valuesPtr, exceptionsPtr,
-                            addToLocalCache, callbackptr);
+          try
+          {
+            m_nativeptr->get()->getAll(vecKeys, valuesPtr, exceptionsPtr, addToLocalCache, callbackptr);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
           if (values != nullptr) {
-            for (apache::geode::client::HashMapOfCacheable::Iterator iter =
+            for (native::HashMapOfCacheable::Iterator iter =
                   valuesPtr->begin(); iter != valuesPtr->end(); ++iter) {
               TKey key = Serializable::GetManagedValueGeneric<TKey>(iter.first());
               TValue val = Serializable::GetManagedValueGeneric<TValue>(iter.second());
@@ -614,7 +749,7 @@ namespace Apache
             }
           }
           if (exceptions != nullptr) {
-            for (apache::geode::client::HashMapOfException::Iterator iter =
+            for (native::HashMapOfException::Iterator iter =
                   exceptionsPtr->begin(); iter != exceptionsPtr->end(); ++iter) {
               TKey key = Serializable::GetManagedValueGeneric<TKey>(iter.first());
               System::Exception^ ex = GeodeException::Get(*iter.second());
@@ -646,14 +781,20 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfCacheableKey vecKeys;
+          native::VectorOfCacheableKey vecKeys;
         for each(TKey item in keys)
           vecKeys.push_back(Serializable::GetUnmanagedValueGeneric<TKey>(item));
 
-        apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
+        native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
 
-        NativePtr->removeAll(vecKeys, callbackptr);
+        try
+        {
+          m_nativeptr->get()->removeAll(vecKeys, callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -661,13 +802,27 @@ namespace Apache
       generic<class TKey, class TValue>
       String^ Region<TKey, TValue>::Name::get()
       {
-        return ManagedString::Get(NativePtr->getName());
+        try
+        {
+          return ManagedString::Get(m_nativeptr->get()->getName());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TValue>
       String^ Region<TKey, TValue>::FullPath::get()
       {
-        return ManagedString::Get(NativePtr->getFullPath());
+        try
+        {
+          return ManagedString::Get(m_nativeptr->get()->getFullPath());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TValue>
@@ -675,9 +830,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::RegionPtr& nativeptr(NativePtr->getParentRegion());
-
-        return Region::Create(nativeptr.get());
+          try
+          {
+            auto parentRegion = m_nativeptr->get()->getParentRegion();
+            return Region::Create(parentRegion);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -687,9 +848,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::RegionAttributesPtr& nativeptr(NativePtr->getAttributes());
-
-        return Apache::Geode::Client::RegionAttributes<TKey, TValue>::Create(nativeptr.get());
+          try
+          {
+            auto nativeptr = m_nativeptr->get()->getAttributes();
+            return Apache::Geode::Client::RegionAttributes<TKey, TValue>::Create(nativeptr);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -699,10 +866,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::AttributesMutatorPtr& nativeptr(
-          NativePtr->getAttributesMutator());
-
-        return Apache::Geode::Client::AttributesMutator<TKey, TValue>::Create(nativeptr.get());
+          try
+          {
+            auto am = m_nativeptr->get()->getAttributesMutator();
+            return Apache::Geode::Client::AttributesMutator<TKey, TValue>::Create( am );
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -712,8 +884,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheStatisticsPtr& nativeptr(NativePtr->getStatistics());
-        return Apache::Geode::Client::CacheStatistics::Create(nativeptr.get());
+          try
+          {
+            auto nativeptr = m_nativeptr->get()->getStatistics();
+            return Apache::Geode::Client::CacheStatistics::Create(nativeptr);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -724,9 +903,15 @@ namespace Apache
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
           ManagedString mg_path(path);
-        apache::geode::client::RegionPtr& nativeptr(
-          NativePtr->getSubregion(mg_path.CharPtr));
-        return Region::Create(nativeptr.get());
+          try
+          {
+            auto subRegion = m_nativeptr->get()->getSubregion(mg_path.CharPtr);
+            return Region::Create(subRegion);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -737,14 +922,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          ManagedString mg_subregionName(subRegionName);
-        //TODO:split
-        apache::geode::client::RegionAttributesPtr p_attrs(
-          GetNativePtrFromSBWrapGeneric<apache::geode::client::RegionAttributes>(attributes));
-
-        apache::geode::client::RegionPtr& nativeptr(NativePtr->createSubregion(
-          mg_subregionName.CharPtr, p_attrs /*nullptr*/));
-        return Region::Create(nativeptr.get());
+          try
+          {
+            ManagedString mg_subregionName(subRegionName);
+            auto p_attrs = attributes->GetNative();
+            return Region::Create(m_nativeptr->get()->createSubregion(mg_subregionName.CharPtr, p_attrs));
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -755,18 +942,24 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfRegion vsr;
-        NativePtr->subregions(recursive, vsr);
+          native::VectorOfRegion vsr;
+        try
+        {
+          m_nativeptr->get()->subregions(recursive, vsr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         array<IRegion<TKey, TValue>^>^ subRegions =
           gcnew array<IRegion<TKey, TValue>^>(vsr.size());
 
         for (System::Int32 index = 0; index < vsr.size(); index++)
         {
-          apache::geode::client::RegionPtr& nativeptr(vsr[index]);
-          subRegions[index] = Region<TKey, TValue>::Create(nativeptr.get());
+          auto subRegion = vsr[index];
+          subRegions[index] = Region<TKey, TValue>::Create(subRegion);
         }
-        System::Collections::Generic::ICollection<IRegion<TKey, TValue>^>^ collection =
-          (System::Collections::Generic::ICollection<IRegion<TKey, TValue>^>^)subRegions;
+        auto collection = (System::Collections::Generic::ICollection<IRegion<TKey, TValue>^>^)subRegions;
         return collection;
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
@@ -777,9 +970,16 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        apache::geode::client::RegionEntryPtr& nativeptr(NativePtr->getEntry(keyptr));
-        return RegionEntry<TKey, TValue>::Create(nativeptr.get());
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          auto nativeptr = m_nativeptr->get()->getEntry(keyptr);
+          return RegionEntry<TKey, TValue>::Create(nativeptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -789,17 +989,23 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfRegionEntry vc;
-        NativePtr->entries(vc, recursive);
+          native::VectorOfRegionEntry vc;
+        try
+        {
+          m_nativeptr->get()->entries(vc, recursive);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         array<RegionEntry<TKey, TValue>^>^ entryarr = gcnew array<RegionEntry<TKey, TValue>^>(vc.size());
 
         for (System::Int32 index = 0; index < vc.size(); index++)
         {
-          apache::geode::client::RegionEntryPtr& nativeptr(vc[index]);
-          entryarr[index] = RegionEntry<TKey, TValue>::Create(nativeptr.get());
+          auto& nativeptr = vc[index];
+          entryarr[index] = RegionEntry<TKey, TValue>::Create(nativeptr);
         }
-        System::Collections::Generic::ICollection<RegionEntry<TKey, TValue>^>^ collection =
-          (System::Collections::Generic::ICollection<RegionEntry<TKey, TValue>^>^)entryarr;
+        auto collection = (System::Collections::Generic::ICollection<RegionEntry<TKey, TValue>^>^)entryarr;
 
         return collection;
 
@@ -812,18 +1018,22 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::RegionServicePtr& nativeptr(NativePtr->getRegionService());
-
-        apache::geode::client::Cache* realCache = dynamic_cast<apache::geode::client::Cache*>(nativeptr.get());
-
-        if (realCache != NULL)
-        {
-          return Apache::Geode::Client::Cache::Create(((apache::geode::client::CachePtr)nativeptr).get());
-        }
-        else
-        {
-          return Apache::Geode::Client::AuthenticatedCache::Create(nativeptr.get());
-        }
+          try
+          {
+            auto regionService = m_nativeptr->get()->getRegionService();
+            if (auto realCache = std::dynamic_pointer_cast<native::Cache>(regionService))
+            {
+              return Apache::Geode::Client::Cache::Create(realCache);
+            }
+            else
+            {
+              return Apache::Geode::Client::AuthenticatedCache::Create(regionService);
+            }
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -833,8 +1043,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheableKeyPtr keyptr(Serializable::GetUnmanagedValueGeneric<TKey>(key));
-        return NativePtr->containsValueForKey(keyptr);
+        try
+        {
+          native::CacheableKeyPtr keyptr = Serializable::GetUnmanagedValueGeneric<TKey>(key);
+          return m_nativeptr->get()->containsValueForKey(keyptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
@@ -843,7 +1060,14 @@ namespace Apache
       int Region<TKey, TValue>::Count::get()
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-          return NativePtr->size();
+          try
+          {
+            return m_nativeptr->get()->size();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
@@ -857,9 +1081,15 @@ namespace Apache
       void Region<TKey, TValue>::Clear(Object^ callbackArg)
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-          apache::geode::client::UserDataPtr callbackptr(
-          Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg));
-        NativePtr->clear(callbackptr);
+        try
+        {
+          native::UserDataPtr callbackptr = Serializable::GetUnmanagedValueGeneric<Object^>(callbackArg);
+          m_nativeptr->get()->clear(callbackptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
@@ -878,8 +1108,15 @@ namespace Apache
 
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfRegionEntry vc;
-        NativePtr->entries(vc, false);
+          native::VectorOfRegionEntry vc;
+        try
+        {
+          m_nativeptr->get()->entries(vc, false);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         if (toArray->Rank > 1 || (vc.size() > (toArray->Length - startIdx)))
         {
@@ -888,9 +1125,9 @@ namespace Apache
 
         for (System::Int32 index = 0; index < vc.size(); index++)
         {
-          apache::geode::client::RegionEntryPtr nativeptr = vc[index];
-          TKey key = Serializable::GetManagedValueGeneric<TKey>(nativeptr->getKey());
-          TValue val = Serializable::GetManagedValueGeneric<TValue>(nativeptr->getValue());
+          auto& nativeptr = vc[index];
+          auto key = Serializable::GetManagedValueGeneric<TKey>(nativeptr->getKey());
+          auto val = Serializable::GetManagedValueGeneric<TValue>(nativeptr->getValue());
           toArray[startIdx] = KeyValuePair<TKey, TValue>(key, val);
           ++startIdx;
         }
@@ -901,7 +1138,14 @@ namespace Apache
       generic<class TKey, class TValue>
       bool Region<TKey, TValue>::IsDestroyed::get()
       {
-        return NativePtr->isDestroyed();
+        try
+        {
+          return m_nativeptr->get()->isDestroyed();
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TValue>
@@ -926,14 +1170,20 @@ namespace Apache
         {
           _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-            apache::geode::client::VectorOfCacheableKey vecKeys;
+            native::VectorOfCacheableKey vecKeys;
 
           for each(TKey item in keys)
           {
-            vecKeys.push_back(
-              Serializable::GetUnmanagedValueGeneric<TKey>(item));
+            vecKeys.push_back(Serializable::GetUnmanagedValueGeneric<TKey>(item));
+          }
+          try
+          {
+            m_nativeptr->get()->registerKeys(vecKeys, isDurable, getInitialValues, receiveValues);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
           }
-          NativePtr->registerKeys(vecKeys, isDurable, getInitialValues, receiveValues);
 
           _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
         }
@@ -946,7 +1196,7 @@ namespace Apache
         {
           _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-            apache::geode::client::VectorOfCacheableKey vecKeys;
+            native::VectorOfCacheableKey vecKeys;
 
           for each(TKey item in keys)
           {
@@ -954,7 +1204,14 @@ namespace Apache
               Serializable::GetUnmanagedValueGeneric<TKey>(item));
           }
 
-          NativePtr->unregisterKeys(vecKeys);
+          try
+          {
+            m_nativeptr->get()->unregisterKeys(vecKeys);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
           _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
         }
@@ -989,9 +1246,16 @@ namespace Apache
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
           if (resultKeys != nullptr) {
-            auto mg_keys = std::make_shared<apache::geode::client::VectorOfCacheableKey>();
+            auto mg_keys = std::make_shared<native::VectorOfCacheableKey>();
 
-            NativePtr->registerAllKeys(isDurable, mg_keys, getInitialValues, receiveValues);
+            try
+            {
+              m_nativeptr->get()->registerAllKeys(isDurable, mg_keys, getInitialValues, receiveValues);
+            }
+            finally
+            {
+              GC::KeepAlive(m_nativeptr);
+            }
 
             for (System::Int32 index = 0; index < mg_keys->size(); ++index) {
               resultKeys->Add(Serializable::GetManagedValueGeneric<TKey>(
@@ -999,7 +1263,14 @@ namespace Apache
             }
           }
           else {
-            NativePtr->registerAllKeys(isDurable, nullptr, getInitialValues, receiveValues);
+            try
+            {
+              m_nativeptr->get()->registerAllKeys(isDurable, nullptr, getInitialValues, receiveValues);
+            }
+            finally
+            {
+              GC::KeepAlive(m_nativeptr);
+            }
           }
 
           _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
@@ -1010,20 +1281,23 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfCacheableKey vc;
-        NativePtr->getInterestList(vc);
-        //List<TValue>^ collectionlist = gcnew List<TValue>(vc.size());
-        array<TKey>^ keyarr =
-          gcnew array<TKey>(vc.size());
+          native::VectorOfCacheableKey vc;
+        try
+        {
+          m_nativeptr->get()->getInterestList(vc);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+        auto keyarr = gcnew array<TKey>(vc.size());
         for (System::Int32 index = 0; index < vc.size(); index++)
         {
-          apache::geode::client::CacheableKeyPtr& nativeptr(vc[index]);
+          auto& nativeptr = vc[index];
           keyarr[index] = Serializable::GetManagedValueGeneric<TKey>(nativeptr);
-          //collectionlist[ index ] = Serializable::GetManagedValueGeneric<TValue>(nativeptr);
         }
 
-        System::Collections::Generic::ICollection<TKey>^ collectionlist =
-          (System::Collections::Generic::ICollection<TKey>^)keyarr;
+        auto collectionlist = (System::Collections::Generic::ICollection<TKey>^)keyarr;
         return collectionlist;
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
@@ -1034,8 +1308,15 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::VectorOfCacheableString vc;
-        NativePtr->getInterestListRegex(vc);
+          native::VectorOfCacheableString vc;
+        try
+        {
+          m_nativeptr->get()->getInterestListRegex(vc);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
         array<String^>^ strarr =
           gcnew array<String^>(vc.size());
         //List<String>^ collectionlist = gcnew List<String>(vc.size());
@@ -1044,8 +1325,7 @@ namespace Apache
           strarr[index] = ManagedString::Get(vc[index]->asChar());
           //collectionlist[ index ] = Serializable::GetManagedValue<TValue>(nativeptr);
         }
-        System::Collections::Generic::ICollection<String^>^ collectionlist =
-          (System::Collections::Generic::ICollection<String^>^)strarr;
+        auto collectionlist = (System::Collections::Generic::ICollection<String^>^)strarr;
         return collectionlist;
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
@@ -1056,7 +1336,14 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          NativePtr->unregisterAllKeys();
+          try
+          {
+            m_nativeptr->get()->unregisterAllKeys();
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -1094,20 +1381,27 @@ namespace Apache
       {
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
+          try
+        {
           ManagedString mg_regex(regex);
-        if (resultKeys != nullptr) {
-          auto mg_keys = std::make_shared<apache::geode::client::VectorOfCacheableKey>();
-          NativePtr->registerRegex(mg_regex.CharPtr, isDurable,
-                                    mg_keys, getInitialValues, receiveValues);
-
-          for (System::Int32 index = 0; index < mg_keys->size(); ++index) {
-            resultKeys->Add(Serializable::GetManagedValueGeneric<TKey>(
-              mg_keys->operator[](index)));
+          if (resultKeys != nullptr) {
+            auto mg_keys = std::make_shared<native::VectorOfCacheableKey>();
+            m_nativeptr->get()->registerRegex(mg_regex.CharPtr, isDurable,
+              mg_keys, getInitialValues, receiveValues);
+
+            for (System::Int32 index = 0; index < mg_keys->size(); ++index) {
+              resultKeys->Add(Serializable::GetManagedValueGeneric<TKey>(
+                mg_keys->operator[](index)));
+            }
+          }
+          else {
+            m_nativeptr->get()->registerRegex(mg_regex.CharPtr, isDurable,
+              nullptr, getInitialValues, receiveValues);
           }
         }
-        else {
-          NativePtr->registerRegex(mg_regex.CharPtr, isDurable,
-                                    nullptr, getInitialValues, receiveValues);
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
         }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
@@ -1119,7 +1413,14 @@ namespace Apache
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
           ManagedString mg_regex(regex);
-        NativePtr->unregisterRegex(mg_regex.CharPtr);
+        try
+        {
+          m_nativeptr->get()->unregisterRegex(mg_regex.CharPtr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -1129,33 +1430,7 @@ namespace Apache
       generic<class TResult>
       ISelectResults<TResult>^ Region<TKey, TValue>::Query(String^ predicate)
       {
-        //return Query( predicate, DEFAULT_QUERY_RESPONSE_TIMEOUT );
-        ManagedString mg_predicate(predicate);
-
-        _GF_MG_EXCEPTION_TRY2/* due to auto replace */
-
-          apache::geode::client::SelectResultsPtr& nativeptr = NativePtr->query(
-          mg_predicate.CharPtr, DEFAULT_QUERY_RESPONSE_TIMEOUT);
-        if (nativeptr.get() == NULL) return nullptr;
-
-        apache::geode::client::ResultSet* resultptr = dynamic_cast<apache::geode::client::ResultSet*>(
-          nativeptr.get());
-        if (resultptr == NULL)
-        {
-          apache::geode::client::StructSet* structptr = dynamic_cast<apache::geode::client::StructSet*>(
-            nativeptr.get());
-          if (structptr == NULL)
-          {
-            return nullptr;
-          }
-          return StructSet<TResult>::Create(structptr);
-        }
-        else
-        {
-          return ResultSet<TResult>::Create(resultptr);
-        }
-        _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
-
+        return Query<TResult>( predicate, DEFAULT_QUERY_RESPONSE_TIMEOUT );
       }
 
       generic<class TKey, class TValue>
@@ -1166,26 +1441,24 @@ namespace Apache
 
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::SelectResultsPtr& nativeptr = NativePtr->query(
-          mg_predicate.CharPtr, timeout);
-        if (nativeptr.get() == NULL) return nullptr;
-
-        apache::geode::client::ResultSet* resultptr = dynamic_cast<apache::geode::client::ResultSet*>(
-          nativeptr.get());
-        if (resultptr == NULL)
-        {
-          apache::geode::client::StructSet* structptr = dynamic_cast<apache::geode::client::StructSet*>(
-            nativeptr.get());
-          if (structptr == NULL)
+          try
           {
+            auto selectResults = m_nativeptr->get()->query(mg_predicate.CharPtr, timeout);
+            if (auto resultptr = std::dynamic_pointer_cast<native::ResultSet>(selectResults))
+            {
+              return ResultSet<TResult>::Create(resultptr);
+            }
+            else if (auto structptr = std::dynamic_pointer_cast<native::StructSet>(selectResults))
+            {
+              return StructSet<TResult>::Create(structptr);
+            }
             return nullptr;
           }
-          return StructSet<TResult>::Create(structptr);
-        }
-        else
-        {
-          return ResultSet<TResult>::Create(resultptr);
-        }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
+
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
       }
 
@@ -1202,7 +1475,14 @@ namespace Apache
 
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          return NativePtr->existsValue(mg_predicate.CharPtr, timeout);
+          try
+          {
+            return m_nativeptr->get()->existsValue(mg_predicate.CharPtr, timeout);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -1221,10 +1501,15 @@ namespace Apache
 
         _GF_MG_EXCEPTION_TRY2/* due to auto replace */
 
-          apache::geode::client::CacheablePtr& nativeptr(NativePtr->selectValue(
-          mg_predicate.CharPtr, timeout));
-
-        return Serializable::GetManagedValueGeneric<Object^>(nativeptr);
+        try
+        {
+          auto nativeptr = m_nativeptr->get()->selectValue(mg_predicate.CharPtr, timeout);
+          return Serializable::GetManagedValueGeneric<Object^>(nativeptr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
 
         _GF_MG_EXCEPTION_CATCH_ALL2/* due to auto replace */
 
@@ -1239,8 +1524,7 @@ namespace Apache
       generic<class TKey, class TValue>
       IRegion<TKey, TValue>^ Region<TKey, TValue>::GetLocalView()
       {
-        return (_NativePtr != nullptr ?
-                gcnew LocalRegion<TKey, TValue>(_NativePtr) : nullptr);
+        return gcnew LocalRegion<TKey, TValue>(GetNative());
       }
     }  // namespace Client
   }  // namespace Geode

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/Region.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/Region.hpp b/src/clicache/src/Region.hpp
index b7b18fe..9aa7c27 100644
--- a/src/clicache/src/Region.hpp
+++ b/src/clicache/src/Region.hpp
@@ -18,16 +18,16 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/Cache.hpp>
-#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+
+
 #include "IRegion.hpp"
-//#include "Log.hpp"
-//#include "ExceptionTypes.hpp"
 #include "ISubscriptionService.hpp"
+#include "native_shared_ptr.hpp"
 
 using namespace System;
-//using namespace System::Collections;
-//using namespace System::Collections::Generic;
 
 namespace Apache
 {
@@ -36,11 +36,10 @@ namespace Apache
     namespace Client
     {
 
-      //generic<class TKey, class TValue>
-     // ref class AttributesMutator;
+      namespace native = apache::geode::client;
 
       generic<class TKey, class TValue>
-			public ref class Region : public Internal::SBWrap<apache::geode::client::Region>,
+			public ref class Region :
         public IRegion<TKey, TValue>,
         public ISubscriptionService<TKey>
       {
@@ -270,11 +269,16 @@ namespace Apache
         /// The managed wrapper object; null if the native pointer is null.
         /// </returns>
         //generic<class TKey, class TValue>
-        inline static Apache::Geode::Client::IRegion<TKey, TValue>^
-        Create( apache::geode::client::Region* nativeptr )
+        inline static IRegion<TKey, TValue>^
+        Create( native::RegionPtr nativeptr )
+        {
+          return __nullptr == nativeptr ? nullptr :
+            gcnew Region<TKey, TValue>( nativeptr );
+        }
+
+        std::shared_ptr<native::Region> GetNative()
         {
-          return ( nativeptr != nullptr ?
-            gcnew Region<TKey, TValue>( nativeptr ) : nullptr );
+          return m_nativeptr->get_shared_ptr();
         }
 
 
@@ -283,14 +287,20 @@ namespace Apache
         /// Private constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline Region( apache::geode::client::Region* nativeptr )
-					: SBWrap<apache::geode::client::Region>( nativeptr ) { }
+        inline Region( native::RegionPtr nativeptr )
+				{
+          m_nativeptr = gcnew native_shared_ptr<native::Region>(nativeptr);
+        }
 
         inline apache::geode::client::SerializablePtr get(apache::geode::client::CacheableKeyPtr& key, apache::geode::client::SerializablePtr& callbackArg);
         inline apache::geode::client::SerializablePtr get(apache::geode::client::CacheableKeyPtr& key);
         bool AreValuesEqual(apache::geode::client::CacheablePtr& val1, apache::geode::client::CacheablePtr& val2);
         bool isPoolInMultiuserMode();
+        
+        native_shared_ptr<native::Region>^ m_nativeptr;
+
       };
+
     }  // namespace Client
   }  // namespace Geode
 }  // namespace Apache

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/RegionAttributes.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/RegionAttributes.cpp b/src/clicache/src/RegionAttributes.cpp
index fe4d12b..7bc639a 100644
--- a/src/clicache/src/RegionAttributes.cpp
+++ b/src/clicache/src/RegionAttributes.cpp
@@ -15,9 +15,7 @@
  * limitations under the License.
  */
 
-//#include "geode_includes.hpp"
 #include "RegionAttributes.hpp"
-//#include "Region.hpp"
 #include "impl/ManagedCacheLoader.hpp"
 #include "impl/ManagedCacheWriter.hpp"
 #include "impl/ManagedCacheListener.hpp"
@@ -44,16 +42,23 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       generic <class TKey, class TValue>
       void Client::RegionAttributes<TKey, TValue>::ToData(
         Apache::Geode::Client::DataOutput^ output )
       {
-        apache::geode::client::DataOutput* nativeOutput =
-          Apache::Geode::Client::GetNativePtrFromUMWrapGeneric<apache::geode::client::DataOutput>( output );
+        auto nativeOutput = output->GetNative();
         if (nativeOutput != nullptr)
         {
-          NativePtr->toData( *nativeOutput );
+          try
+          {
+            m_nativeptr->get()->toData(*nativeOutput);
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
       }
 
@@ -61,12 +66,21 @@ namespace Apache
       Apache::Geode::Client::IGeodeSerializable^ Client::RegionAttributes<TKey, TValue>::FromData(
         Apache::Geode::Client::DataInput^ input )
       {
-        apache::geode::client::DataInput* nativeInput =
-          Apache::Geode::Client::GetNativePtrFromUMWrapGeneric<apache::geode::client::DataInput>( input );
+        auto nativeInput = input->GetNative();
         if (nativeInput != nullptr)
         {
-          AssignPtr( static_cast<apache::geode::client::RegionAttributes*>(
-            NativePtr->fromData( *nativeInput ) ) );
+          try
+          {
+            auto temp = static_cast<native::RegionAttributes*>(m_nativeptr->get()->fromData(*nativeInput));
+            if (temp != m_nativeptr->get())
+            {
+              m_nativeptr->get_shared_ptr().reset(temp);
+            }
+          }
+          finally
+          {
+            GC::KeepAlive(m_nativeptr);
+          }
         }
         return this;
       }
@@ -74,286 +88,517 @@ namespace Apache
       generic <class TKey, class TValue>
       ICacheLoader<TKey, TValue>^ Client::RegionAttributes<TKey, TValue>::CacheLoader::get()
       {
-        apache::geode::client::CacheLoaderPtr& loaderptr( NativePtr->getCacheLoader( ) );
-        apache::geode::client::ManagedCacheLoaderGeneric* mg_loader =
-          dynamic_cast<apache::geode::client::ManagedCacheLoaderGeneric*>( loaderptr.ptr( ) );
-
-        if (mg_loader != nullptr)
+        try
+        {
+          auto loaderptr = m_nativeptr->get()->getCacheLoader();
+          if (auto mg_loader = std::dynamic_pointer_cast<native::ManagedCacheLoaderGeneric>(loaderptr))
+          {
+            return (ICacheLoader<TKey, TValue>^) mg_loader->userptr();
+          }
+          return nullptr;
+        }
+        finally
         {
-          return (ICacheLoader<TKey, TValue>^) mg_loader->userptr( );
+          GC::KeepAlive(m_nativeptr);
         }
-        return nullptr;
       }
 
       generic <class TKey, class TValue>
       ICacheWriter<TKey, TValue>^ Client::RegionAttributes<TKey, TValue>::CacheWriter::get()
       {
-        apache::geode::client::CacheWriterPtr& writerptr( NativePtr->getCacheWriter( ) );
-        apache::geode::client::ManagedCacheWriterGeneric* mg_writer =
-          dynamic_cast<apache::geode::client::ManagedCacheWriterGeneric*>( writerptr.ptr( ) );
-
-        if (mg_writer != nullptr)
+        try
+        {
+          auto writerptr = m_nativeptr->get()->getCacheWriter();
+          if (auto mg_writer = std::dynamic_pointer_cast<native::ManagedCacheWriterGeneric>(writerptr))
+          {
+            return (ICacheWriter<TKey, TValue>^)mg_writer->userptr();
+          }
+          return nullptr;
+        }
+        finally
         {
-          return (ICacheWriter<TKey, TValue>^)mg_writer->userptr( );
+          GC::KeepAlive(m_nativeptr);
         }
-        return nullptr;
       }
 
       generic <class TKey, class TValue>
       ICacheListener<TKey, TValue>^ Client::RegionAttributes<TKey, TValue>::CacheListener::get()
       {
-        apache::geode::client::CacheListenerPtr& listenerptr( NativePtr->getCacheListener( ) );
-        apache::geode::client::ManagedCacheListenerGeneric* mg_listener =
-          dynamic_cast<apache::geode::client::ManagedCacheListenerGeneric*>( listenerptr.ptr( ) );
-
-        if (mg_listener != nullptr)
+        try
         {
-          /*
-          CacheListenerGeneric<TKey, TValue>^ clg = gcnew CacheListenerGeneric<TKey, TValue>();
-          clg->SetCacheListener((ICacheListener<TKey, TValue>^)mg_listener->userptr());
-          mg_listener->setptr(clg);
-          */
-          return (ICacheListener<TKey, TValue>^)mg_listener->userptr( );
+          auto listenerptr = m_nativeptr->get()->getCacheListener();
+          if (auto mg_listener = std::dynamic_pointer_cast<native::ManagedCacheListenerGeneric>(listenerptr))
+          {
+            return (ICacheListener<TKey, TValue>^)mg_listener->userptr();
+          }
+          return nullptr;
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
         }
-        return nullptr;
       }
 
       generic <class TKey, class TValue>
       IPartitionResolver<TKey, TValue>^ Client::RegionAttributes<TKey, TValue>::PartitionResolver::get()
       {
-        apache::geode::client::PartitionResolverPtr& resolverptr( NativePtr->getPartitionResolver( ) );
-        apache::geode::client::ManagedPartitionResolverGeneric* mg_resolver =
-          dynamic_cast<apache::geode::client::ManagedPartitionResolverGeneric*>( resolverptr.ptr( ) );
-
-        if (mg_resolver != nullptr)
+        try
         {
-          return (IPartitionResolver<TKey, TValue>^)mg_resolver->userptr( );
+          auto resolverptr = m_nativeptr->get()->getPartitionResolver();
+          if (auto mg_resolver = std::dynamic_pointer_cast<native::ManagedPartitionResolverGeneric>(resolverptr))
+          {
+            return (IPartitionResolver<TKey, TValue>^)mg_resolver->userptr();
+          }
+
+          if (auto mg_fixedResolver = std::dynamic_pointer_cast<native::ManagedFixedPartitionResolverGeneric>(resolverptr))
+          {
+            return (IPartitionResolver<TKey, TValue>^)mg_fixedResolver->userptr();
+          }
+
+          return nullptr;
         }
-
-        apache::geode::client::ManagedFixedPartitionResolverGeneric* mg_fixedResolver =
-          dynamic_cast<apache::geode::client::ManagedFixedPartitionResolverGeneric*>( resolverptr.ptr( ) );
-
-        if (mg_fixedResolver != nullptr)
+        finally
         {
-          return (IPartitionResolver<TKey, TValue>^)mg_fixedResolver->userptr( );
+          GC::KeepAlive(m_nativeptr);
         }
-
-        return nullptr;
       }
 
       generic <class TKey, class TValue>
       System::Int32 Client::RegionAttributes<TKey, TValue>::RegionTimeToLive::get()
       {
-        return NativePtr->getRegionTimeToLive( );
+        try
+        {
+          return m_nativeptr->get()->getRegionTimeToLive( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       ExpirationAction Client::RegionAttributes<TKey, TValue>::RegionTimeToLiveAction::get()
       {
-        return static_cast<ExpirationAction>( NativePtr->getRegionTimeToLiveAction( ) );
+        try
+        {
+          return static_cast<ExpirationAction>( m_nativeptr->get()->getRegionTimeToLiveAction( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       System::Int32 Client::RegionAttributes<TKey, TValue>::RegionIdleTimeout::get()
       {
-        return NativePtr->getRegionIdleTimeout( );
+        try
+        {
+          return m_nativeptr->get()->getRegionIdleTimeout( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       ExpirationAction Client::RegionAttributes<TKey, TValue>::RegionIdleTimeoutAction::get()
       {
-        return static_cast<ExpirationAction>( NativePtr->getRegionIdleTimeoutAction( ) );
+        try
+        {
+          return static_cast<ExpirationAction>( m_nativeptr->get()->getRegionIdleTimeoutAction( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       System::Int32 Client::RegionAttributes<TKey, TValue>::EntryTimeToLive::get()
       {
-        return NativePtr->getEntryTimeToLive( );
+        try
+        {
+          return m_nativeptr->get()->getEntryTimeToLive( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       ExpirationAction Client::RegionAttributes<TKey, TValue>::EntryTimeToLiveAction::get()
       {
-        return static_cast<ExpirationAction>( NativePtr->getEntryTimeToLiveAction( ) );
+        try
+        {
+          return static_cast<ExpirationAction>( m_nativeptr->get()->getEntryTimeToLiveAction( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       System::Int32 Client::RegionAttributes<TKey, TValue>::EntryIdleTimeout::get()
       {
-        return NativePtr->getEntryIdleTimeout( );
+        try
+        {
+          return m_nativeptr->get()->getEntryIdleTimeout( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       ExpirationAction Client::RegionAttributes<TKey, TValue>::EntryIdleTimeoutAction::get()
       {
-        return static_cast<ExpirationAction>( NativePtr->getEntryIdleTimeoutAction( ) );
+        try
+        {
+          return static_cast<ExpirationAction>( m_nativeptr->get()->getEntryIdleTimeoutAction( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       bool Client::RegionAttributes<TKey, TValue>::CachingEnabled::get()
       {
-        return NativePtr->getCachingEnabled( );
+        try
+        {
+          return m_nativeptr->get()->getCachingEnabled( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       bool Client::RegionAttributes<TKey, TValue>::CloningEnabled::get()
       {
-        return NativePtr->getCloningEnabled( );
+        try
+        {
+          return m_nativeptr->get()->getCloningEnabled( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       System::Int32 Client::RegionAttributes<TKey, TValue>::InitialCapacity::get()
       {
-        return NativePtr->getInitialCapacity( );
+        try
+        {
+          return m_nativeptr->get()->getInitialCapacity( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       Single Client::RegionAttributes<TKey, TValue>::LoadFactor::get()
       {
-        return NativePtr->getLoadFactor( );
+        try
+        {
+          return m_nativeptr->get()->getLoadFactor( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
         System::Int32 Client::RegionAttributes<TKey, TValue>::ConcurrencyLevel::get()
       {
-        return NativePtr->getConcurrencyLevel( );
+        try
+        {
+          return m_nativeptr->get()->getConcurrencyLevel( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       System::UInt32 Client::RegionAttributes<TKey, TValue>::LruEntriesLimit::get()
       {
-        return NativePtr->getLruEntriesLimit( );
+        try
+        {
+          return m_nativeptr->get()->getLruEntriesLimit( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       DiskPolicyType Client::RegionAttributes<TKey, TValue>::DiskPolicy::get()
       {
-        return static_cast<DiskPolicyType>( NativePtr->getDiskPolicy( ) );
+        try
+        {
+          return static_cast<DiskPolicyType>( m_nativeptr->get()->getDiskPolicy( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       ExpirationAction Client::RegionAttributes<TKey, TValue>::LruEvictionAction::get()
       {
-        return static_cast<ExpirationAction>( NativePtr->getLruEvictionAction( ) );
+        try
+        {
+          return static_cast<ExpirationAction>( m_nativeptr->get()->getLruEvictionAction( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::CacheLoaderLibrary::get()
       {
-        return ManagedString::Get( NativePtr->getCacheLoaderLibrary( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getCacheLoaderLibrary( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::CacheLoaderFactory::get()
       {
-        return ManagedString::Get( NativePtr->getCacheLoaderFactory( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getCacheLoaderFactory( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::CacheListenerLibrary::get()
       {
-        return ManagedString::Get( NativePtr->getCacheListenerLibrary( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getCacheListenerLibrary( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::PartitionResolverLibrary::get()
       {
-        return ManagedString::Get( NativePtr->getPartitionResolverLibrary( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getPartitionResolverLibrary( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::PartitionResolverFactory::get()
       {
-        return ManagedString::Get( NativePtr->getPartitionResolverFactory( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getPartitionResolverFactory( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::CacheListenerFactory::get()
       {
-        return ManagedString::Get( NativePtr->getCacheListenerFactory( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getCacheListenerFactory( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::CacheWriterLibrary::get()
       {
-        return ManagedString::Get( NativePtr->getCacheWriterLibrary( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getCacheWriterLibrary( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::CacheWriterFactory::get()
       {
-        return ManagedString::Get( NativePtr->getCacheWriterFactory( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getCacheWriterFactory( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       bool Client::RegionAttributes<TKey, TValue>::Equals(Client::RegionAttributes<TKey, TValue>^ other)
       {
-        apache::geode::client::RegionAttributes* otherPtr =
-          GetNativePtrFromSBWrapGeneric<apache::geode::client::RegionAttributes>( other );
-        if (_NativePtr != nullptr && otherPtr != nullptr) {
-          return NativePtr->operator==(*otherPtr);
+        auto otherPtr = other->GetNative();
+        try
+        {
+          if (GetNative() != __nullptr && otherPtr != __nullptr) {
+            return m_nativeptr->get()->operator==(*otherPtr);
+          }
+          return (GetNative() == otherPtr);
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
         }
-        return (_NativePtr == otherPtr);
       }
 
       generic <class TKey, class TValue>
       bool Client::RegionAttributes<TKey, TValue>::Equals(Object^ other)
       {
-        apache::geode::client::RegionAttributes* otherPtr = GetNativePtrFromSBWrapGeneric<apache::geode::client::
-          RegionAttributes>( dynamic_cast<Client::RegionAttributes<TKey, TValue>^>( other ) );
-        if (_NativePtr != nullptr && otherPtr != nullptr) {
-          return NativePtr->operator==(*otherPtr);
-        }
-        return (_NativePtr == otherPtr);
+        return Equals(dynamic_cast<Client::RegionAttributes<TKey, TValue>^>(other));
       }
 
       generic <class TKey, class TValue>
       void Client::RegionAttributes<TKey, TValue>::ValidateSerializableAttributes()
       {
-        NativePtr->validateSerializableAttributes( );
+        try
+        {
+          m_nativeptr->get()->validateSerializableAttributes( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::Endpoints::get()
       {
-        return ManagedString::Get( NativePtr->getEndpoints( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getEndpoints( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::PoolName::get()
       {
-        return ManagedString::Get( NativePtr->getPoolName( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getPoolName( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       Boolean Client::RegionAttributes<TKey, TValue>::ClientNotificationEnabled::get()
       {
-        return NativePtr->getClientNotificationEnabled( );
+        try
+        {
+          return m_nativeptr->get()->getClientNotificationEnabled( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::PersistenceLibrary::get()
       {
-        return ManagedString::Get( NativePtr->getPersistenceLibrary( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getPersistenceLibrary( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       String^ Client::RegionAttributes<TKey, TValue>::PersistenceFactory::get()
       {
-        return ManagedString::Get( NativePtr->getPersistenceFactory( ) );
+        try
+        {
+          return ManagedString::Get( m_nativeptr->get()->getPersistenceFactory( ) );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
       generic <class TKey, class TValue>
       bool Client::RegionAttributes<TKey, TValue>::ConcurrencyChecksEnabled::get()
       {
-        return NativePtr->getConcurrencyChecksEnabled( );
+        try
+        {
+          return m_nativeptr->get()->getConcurrencyChecksEnabled( );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic <class TKey, class TValue>
       Properties<String^, String^>^Client::RegionAttributes<TKey, TValue>::PersistenceProperties::get()
       {
-        apache::geode::client::PropertiesPtr& nativeptr(
-          NativePtr->getPersistenceProperties());
-        return Properties<String^, String^>::Create<String^, String^>(nativeptr.get());
+        try
+        {
+          return Properties<String^, String^>::Create(m_nativeptr->get()->getPersistenceProperties());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
     }  // namespace Client
   }  // namespace Geode

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/RegionAttributes.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/RegionAttributes.hpp b/src/clicache/src/RegionAttributes.hpp
index 05e413f..da47fc3 100644
--- a/src/clicache/src/RegionAttributes.hpp
+++ b/src/clicache/src/RegionAttributes.hpp
@@ -18,8 +18,11 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/RegionAttributes.hpp>
-//#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+
+#include "native_shared_ptr.hpp"
 #include "IGeodeSerializable.hpp"
 #include "ExpirationAction.hpp"
 #include "DiskPolicyType.hpp"
@@ -39,11 +42,7 @@ namespace Apache
   {
     namespace Client
     {
-
-      //interface class ICacheLoader;
-      //interface class ICacheWriter;
-      //interface class ICacheListener;
-      //interface class IPartitionResolver;
+      namespace native = apache::geode::client;
 
       /// <summary>
       /// Defines attributes for configuring a region.
@@ -68,7 +67,7 @@ namespace Apache
       /// <seealso cref="Region.Attributes" />
       generic <class TKey, class TValue>
       public ref class RegionAttributes sealed
-        : public Client::Internal::SBWrap<apache::geode::client::RegionAttributes>, public IGeodeSerializable
+        : public IGeodeSerializable
       {
       public:
 
@@ -481,12 +480,16 @@ namespace Apache
         /// <returns>
         /// The managed wrapper object; null if the native pointer is null.
         /// </returns>
-        inline static RegionAttributes<TKey, TValue>^ Create(apache::geode::client::RegionAttributes* nativeptr)
+        inline static RegionAttributes<TKey, TValue>^ Create(native::RegionAttributesPtr nativeptr)
         {
-          return (nativeptr != nullptr ?
-                  gcnew RegionAttributes<TKey, TValue>(nativeptr) : nullptr);
+          return __nullptr == nativeptr ? nullptr :
+            gcnew RegionAttributes<TKey, TValue>( nativeptr );
         }
 
+        std::shared_ptr<native::RegionAttributes> GetNative()
+        {
+          return m_nativeptr->get_shared_ptr();
+        }
 
       private:
 
@@ -494,8 +497,12 @@ namespace Apache
         /// Private constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline RegionAttributes<TKey, TValue>(apache::geode::client::RegionAttributes* nativeptr)
-          : SBWrap(nativeptr) { }
+        inline RegionAttributes<TKey, TValue>(native::RegionAttributesPtr nativeptr)
+        {
+          m_nativeptr = gcnew native_shared_ptr<native::RegionAttributes>(nativeptr);
+        }
+
+        native_shared_ptr<native::RegionAttributes>^ m_nativeptr;
       };
     }  // namespace Client
   }  // namespace Geode

http://git-wip-us.apache.org/repos/asf/geode-native/blob/6027574a/src/clicache/src/RegionEntry.cpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/RegionEntry.cpp b/src/clicache/src/RegionEntry.cpp
index cfde37d..95b5b57 100644
--- a/src/clicache/src/RegionEntry.cpp
+++ b/src/clicache/src/RegionEntry.cpp
@@ -32,44 +32,70 @@ namespace Apache
 
       generic<class TKey, class TValue>
       TKey RegionEntry<TKey, TValue>::Key::get( )
-      {
-        apache::geode::client::CacheableKeyPtr& nativeptr( NativePtr->getKey( ) );
-        
-        return Serializable::GetManagedValueGeneric<TKey>( nativeptr );
+      {        
+        try
+        {
+          return Serializable::GetManagedValueGeneric<TKey>(m_nativeptr->get()->getKey());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TValue>
       TValue RegionEntry<TKey, TValue>::Value::get( )
       {
-        apache::geode::client::CacheablePtr& nativeptr( NativePtr->getValue( ) );
-
-        return Serializable::GetManagedValueGeneric<TValue>( nativeptr );
+        try
+        {
+          return Serializable::GetManagedValueGeneric<TValue>(m_nativeptr->get()->getValue());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TValue>
       IRegion<TKey, TValue>^ RegionEntry<TKey, TValue>::Region::get( )
       {
-        apache::geode::client::RegionPtr rptr;
-
-        NativePtr->getRegion( rptr );
-        return Apache::Geode::Client::Region<TKey, TValue>::Create( rptr.ptr( ) );
+        try
+        {
+          return Apache::Geode::Client::Region<TKey, TValue>::Create(m_nativeptr->get()->getRegion());
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
       }
 
       generic<class TKey, class TValue>
       Apache::Geode::Client::CacheStatistics^ RegionEntry<TKey, TValue>::Statistics::get( )
       {
         apache::geode::client::CacheStatisticsPtr nativeptr;
-
-        NativePtr->getStatistics( nativeptr );
-        return Apache::Geode::Client::CacheStatistics::Create( nativeptr.ptr( ) );
+        try
+        {
+          m_nativeptr->get()->getStatistics( nativeptr );
+        }
+        finally
+        {
+          GC::KeepAlive(m_nativeptr);
+        }
+        return Apache::Geode::Client::CacheStatistics::Create( nativeptr);
       }
 
       generic<class TKey, class TValue>
       bool RegionEntry<TKey, TValue>::IsDestroyed::get( )
       {
-        return NativePtr->isDestroyed( );
+        try
+        {
+          return m_nativeptr->get()->isDestroyed( );
+        }
+        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/RegionEntry.hpp
----------------------------------------------------------------------
diff --git a/src/clicache/src/RegionEntry.hpp b/src/clicache/src/RegionEntry.hpp
index 767a052..85c933f 100644
--- a/src/clicache/src/RegionEntry.hpp
+++ b/src/clicache/src/RegionEntry.hpp
@@ -18,8 +18,11 @@
 #pragma once
 
 #include "geode_defs.hpp"
+#include "begin_native.hpp"
 #include <geode/RegionEntry.hpp>
-#include "impl/NativeWrapper.hpp"
+#include "end_native.hpp"
+
+#include "native_shared_ptr.hpp"
 //#include "ICacheableKey.hpp"
 #include "IRegion.hpp"
 
@@ -31,6 +34,7 @@ namespace Apache
   {
     namespace Client
     {
+      namespace native = apache::geode::client;
 
       //ref class Region;
       ref class CacheStatistics;
@@ -51,7 +55,6 @@ namespace Apache
       /// </remarks>
       generic<class TKey, class TValue>
       public ref class RegionEntry sealed
-        : public Internal::SBWrap<apache::geode::client::RegionEntry>
       {
       public:
 
@@ -159,10 +162,10 @@ namespace Apache
         /// <returns>
         /// The managed wrapper object; null if the native pointer is null.
         /// </returns>
-        inline static Client::RegionEntry<TKey, TValue>^ Create( apache::geode::client::RegionEntry* nativeptr )
+        inline static Client::RegionEntry<TKey, TValue>^ Create( native::RegionEntryPtr nativeptr )
         {
-          return ( nativeptr != nullptr ?
-            gcnew Client::RegionEntry<TKey, TValue>( nativeptr ) : nullptr );
+         return __nullptr == nativeptr ? nullptr :
+            gcnew RegionEntry<TKey, TValue>( nativeptr );
         }
 
 
@@ -172,8 +175,12 @@ namespace Apache
         /// Private constructor to wrap a native object pointer
         /// </summary>
         /// <param name="nativeptr">The native object pointer</param>
-        inline RegionEntry( apache::geode::client::RegionEntry* nativeptr )
-          : SBWrap( nativeptr ) { }
+        inline RegionEntry( native::RegionEntryPtr nativeptr )
+        {
+          m_nativeptr = gcnew native_shared_ptr<native::RegionEntry>(nativeptr);
+        }
+
+        native_shared_ptr<native::RegionEntry>^ m_nativeptr; 
       };
     }  // namespace Client
   }  // namespace Geode


Mime
View raw message