diff --git a/zUtil_Cxx/include/GtMatlabVolumeLooper.h b/zUtil_Cxx/include/GtMatlabVolumeLooper.h
index 965a0feceb19c26bdd34314d581d3edc80d83c1d..6deccb761f59ba9b505efa8c3f0ab66acb1ce79e 100644
--- a/zUtil_Cxx/include/GtMatlabVolumeLooper.h
+++ b/zUtil_Cxx/include/GtMatlabVolumeLooper.h
@@ -10,6 +10,14 @@
 
 #include "mex.h"
 
+extern "C"
+{
+  bool mxUnshareArray(mxArray *array_ptr, bool noDeepCopy);
+  mxArray *mxCreateSharedCopy(const mxArray *pr);
+  mxArray *mxCreateSharedDataCopy(const mxArray *pr);
+  mxArray *mxUnreference(const mxArray *pr);
+}
+
 template<typename Type>
 class GtMatlabPointer {
   const mwSize multiplier;
diff --git a/zUtil_Cxx/internal_gtAssignGrainToVol.cpp b/zUtil_Cxx/internal_gtAssignGrainToVol.cpp
index 126fa44f82ac7972e9f21a9b86b5bda8ea2afc32..1ba3d5ca8f3aabde1dfc6857744d82a7be05396a 100644
--- a/zUtil_Cxx/internal_gtAssignGrainToVol.cpp
+++ b/zUtil_Cxx/internal_gtAssignGrainToVol.cpp
@@ -74,7 +74,7 @@ void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] )
   /* -- No assert on correctness of parameters -- */
 
   /* Don't copy, just modify the incoming matrix */
-  plhs[0] = (mxArray *) prhs[0];
+  plhs[0] = mxCreateSharedDataCopy(prhs[0]);
 
   switch(mxGetClassID(prhs[1])) {
     case mxDOUBLE_CLASS: {
diff --git a/zUtil_Cxx/internal_gtAssignGrainToVol_interf.cpp b/zUtil_Cxx/internal_gtAssignGrainToVol_interf.cpp
index 69763c78a578ba25de7826b0dfa2533df0bf6f15..a78b63c7ae8bf1827109130cd0b8e4f9f874f437 100644
--- a/zUtil_Cxx/internal_gtAssignGrainToVol_interf.cpp
+++ b/zUtil_Cxx/internal_gtAssignGrainToVol_interf.cpp
@@ -75,7 +75,7 @@ void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] )
   /* -- No assert on correctness of parameters -- */
 
   /* Don't copy, just modify the incoming matrix */
-  plhs[0] = (mxArray *) prhs[0];
+  plhs[0] = mxCreateSharedDataCopy(prhs[0]);
 
   switch(mxGetClassID(prhs[1])) {
     case mxDOUBLE_CLASS: {
diff --git a/zUtil_Cxx/internal_gtAssignGrainToVol_sum.cpp b/zUtil_Cxx/internal_gtAssignGrainToVol_sum.cpp
index 83c2cc39fd6369dbefc3a906bebdbf5a81d44b2a..9aa301eefd60dd8eb49504d4c5607617924625f4 100644
--- a/zUtil_Cxx/internal_gtAssignGrainToVol_sum.cpp
+++ b/zUtil_Cxx/internal_gtAssignGrainToVol_sum.cpp
@@ -73,7 +73,7 @@ void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] )
   /* -- No assert on correctness of parameters -- */
 
   /* Don't copy, just modify the incoming matrix */
-  plhs[0] = (mxArray *) prhs[0];
+  plhs[0] = mxCreateSharedDataCopy(prhs[0]);
 
   switch(mxGetClassID(prhs[1])) {
     case mxDOUBLE_CLASS: {
diff --git a/zUtil_Cxx/internal_gtDilateGrains_voxel.cpp b/zUtil_Cxx/internal_gtDilateGrains_voxel.cpp
index 22504c8ece6ac9b51e7718e35f2732988e46fa9b..e572abf0d814c9447a527af052dc9ad0ef0e75d1 100644
--- a/zUtil_Cxx/internal_gtDilateGrains_voxel.cpp
+++ b/zUtil_Cxx/internal_gtDilateGrains_voxel.cpp
@@ -83,7 +83,7 @@ void mexFunction( int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[] )
   /* -- No assert on correctness of parameters -- */
 
   /* Don't copy, just modify the incoming matrix */
-  plhs[0] = (mxArray *) prhs[0];
+  plhs[0] = mxCreateSharedDataCopy(prhs[0]);
 
   switch(mxGetClassID(prhs[1])) {
     case mxDOUBLE_CLASS: {