Index: branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibCommon/TComPic.cpp	(revision 1540)
@@ -75,8 +75,11 @@
 TComPic::~TComPic()
 {
+  destroy();
 }
 #if SVC_EXTENSION
 Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual, const UInt layerId )
 {
+  destroy();
+
   const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
   const Int          iWidth          = sps.getPicWidthInLumaSamples();
@@ -116,4 +119,6 @@
 Void TComPic::create( const TComSPS &sps, const TComPPS &pps, const Bool bIsVirtual)
 {
+  destroy();
+
   const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
   const Int          iWidth          = sps.getPicWidthInLumaSamples();
Index: branches/SHM-dev/source/Lib/TLibCommon/TComPicSym.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TComPicSym.cpp	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibCommon/TComPicSym.cpp	(revision 1540)
@@ -77,4 +77,10 @@
 {}
 
+
+TComPicSym::~TComPicSym()
+{
+  destroy();
+}
+
 #if SVC_EXTENSION
 Void TComPicSym::create  ( const TComSPS &sps, const TComPPS &pps, UInt uiMaxDepth, const UInt layerId )
@@ -84,5 +90,6 @@
 {
 #endif
-  UInt i;
+  destroy();
+
   m_sps = sps;
   m_pps = pps;
@@ -91,5 +98,4 @@
   const Int iPicWidth      = sps.getPicWidthInLumaSamples();
   const Int iPicHeight     = sps.getPicHeightInLumaSamples();
-
   const UInt uiMaxCuWidth  = sps.getMaxCUWidth();
   const UInt uiMaxCuHeight = sps.getMaxCUHeight();
@@ -124,5 +130,5 @@
 #endif
 
-  for ( i=0; i<m_numCtusInFrame ; i++ )
+  for (UInt i=0; i<m_numCtusInFrame ; i++ )
   {
     m_pictureCtuArray[i] = new TComDataCU;
@@ -144,5 +150,5 @@
 #endif  
 
-  for( i=0; i<m_numCtusInFrame; i++ )
+  for(UInt i=0; i<m_numCtusInFrame; i++ )
   {
     m_ctuTsToRsAddrMap[i] = i;
Index: branches/SHM-dev/source/Lib/TLibCommon/TComPicSym.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TComPicSym.h	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibCommon/TComPicSym.h	(revision 1540)
@@ -140,4 +140,6 @@
 
   TComPicSym  ();
+  ~TComPicSym();
+
   TComSlice*         getSlice(UInt i)                                      { return m_apSlices[i];             }
   const TComSlice*   getSlice(UInt i) const                                { return m_apSlices[i];             }
Index: branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibCommon/TComPicYuv.cpp	(revision 1540)
@@ -74,4 +74,5 @@
 TComPicYuv::~TComPicYuv()
 {
+  destroy();
 }
 
@@ -90,4 +91,5 @@
 
 {
+  destroy();
 
 #if SVC_EXTENSION
Index: branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibCommon/TComYuv.cpp	(revision 1540)
@@ -59,8 +59,10 @@
 TComYuv::~TComYuv()
 {
+  destroy();
 }
 
 Void TComYuv::create( UInt iWidth, UInt iHeight, ChromaFormat chromaFormatIDC )
 {
+  destroy();
   // set width and height
   m_iWidth   = iWidth;
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp	(revision 1540)
@@ -3587,6 +3587,6 @@
   assert(noCol > 1);
   assert(noRows > 1);
-  UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64));
-  UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64));
+  std::vector<UInt64> colSAD(noCol, UInt64(0));
+  std::vector<UInt64> rowSAD(noCol, UInt64(0));
   UInt colIdx = 0;
   UInt rowIdx = 0;
@@ -3600,7 +3600,4 @@
   const Int thr1 = 2*bitdepthScale;
   UInt a = 0;
-
-  memset(colSAD, 0, noCol*sizeof(UInt64));
-  memset(rowSAD, 0, noRows*sizeof(UInt64));
 
   if (maxTBsize > minBlockArtSize)
@@ -3692,7 +3689,4 @@
     }
   }
-
-  free(colSAD);
-  free(rowSAD);
 }
 
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp	(revision 1540)
@@ -50,14 +50,9 @@
  : m_encCABACTableIdx(I_SLICE)
 {
-  m_apcPicYuvPred = NULL;
-  m_apcPicYuvResi = NULL;
-
-  m_pdRdPicLambda = NULL;
-  m_pdRdPicQp     = NULL;
-  m_piRdPicQp     = NULL;
 }
 
 TEncSlice::~TEncSlice()
 {
+  destroy();
 }
 
@@ -65,52 +60,19 @@
 {
   // create prediction picture
-  if ( m_apcPicYuvPred == NULL )
-  {
-    m_apcPicYuvPred  = new TComPicYuv;
-    m_apcPicYuvPred->create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth, true );
-  }
+  m_picYuvPred.create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth, true );
 
   // create residual picture
-  if( m_apcPicYuvResi == NULL )
-  {
-    m_apcPicYuvResi  = new TComPicYuv;
-    m_apcPicYuvResi->create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth, true );
-  }
+  m_picYuvResi.create( iWidth, iHeight, chromaFormat, iMaxCUWidth, iMaxCUHeight, uhTotalDepth, true );
 }
 
 Void TEncSlice::destroy()
 {
-  // destroy prediction picture
-  if ( m_apcPicYuvPred )
-  {
-    m_apcPicYuvPred->destroy();
-    delete m_apcPicYuvPred;
-    m_apcPicYuvPred  = NULL;
-  }
-
-  // destroy residual picture
-  if ( m_apcPicYuvResi )
-  {
-    m_apcPicYuvResi->destroy();
-    delete m_apcPicYuvResi;
-    m_apcPicYuvResi  = NULL;
-  }
+  m_picYuvPred.destroy();
+  m_picYuvResi.destroy();
 
   // free lambda and QP arrays
-  if ( m_pdRdPicLambda )
-  {
-    xFree( m_pdRdPicLambda );
-    m_pdRdPicLambda = NULL;
-  }
-  if ( m_pdRdPicQp )
-  {
-    xFree( m_pdRdPicQp );
-    m_pdRdPicQp = NULL;
-  }
-  if ( m_piRdPicQp )
-  {
-    xFree( m_piRdPicQp );
-    m_piRdPicQp = NULL;
-  }
+  m_vdRdPicLambda.clear();
+  m_vdRdPicQp.clear();
+  m_viRdPicQp.clear();
 }
 
@@ -134,7 +96,7 @@
 
   // create lambda and QP arrays
-  m_pdRdPicLambda     = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
-  m_pdRdPicQp         = (Double*)xMalloc( Double, m_pcCfg->getDeltaQpRD() * 2 + 1 );
-  m_piRdPicQp         = (Int*   )xMalloc( Int,    m_pcCfg->getDeltaQpRD() * 2 + 1 );
+  m_vdRdPicLambda.resize(m_pcCfg->getDeltaQpRD() * 2 + 1 );
+  m_vdRdPicQp.resize(    m_pcCfg->getDeltaQpRD() * 2 + 1 );
+  m_viRdPicQp.resize(    m_pcCfg->getDeltaQpRD() * 2 + 1 );
   m_pcRateCtrl        = pcEncTop->getRateCtrl();
 
@@ -416,13 +378,13 @@
     iQP = max( -rpcSlice->getSPS()->getQpBDOffset(CHANNEL_TYPE_LUMA), min( MAX_QP, (Int) floor( dQP + 0.5 ) ) );
 
-    m_pdRdPicLambda[iDQpIdx] = dLambda;
-    m_pdRdPicQp    [iDQpIdx] = dQP;
-    m_piRdPicQp    [iDQpIdx] = iQP;
+    m_vdRdPicLambda[iDQpIdx] = dLambda;
+    m_vdRdPicQp    [iDQpIdx] = dQP;
+    m_viRdPicQp    [iDQpIdx] = iQP;
   }
 
   // obtain dQP = 0 case
-  dLambda = m_pdRdPicLambda[0];
-  dQP     = m_pdRdPicQp    [0];
-  iQP     = m_piRdPicQp    [0];
+  dLambda = m_vdRdPicLambda[0];
+  dQP     = m_vdRdPicQp    [0];
+  iQP     = m_viRdPicQp    [0];
 
   const Int temporalId=m_pcCfg->getGOPEntry(iGOPid).m_temporalId;
@@ -536,9 +498,6 @@
   rpcSlice->setTLayer( pcPic->getTLayer() );
 
-  assert( m_apcPicYuvPred );
-  assert( m_apcPicYuvResi );
-
-  pcPic->setPicYuvPred( m_apcPicYuvPred );
-  pcPic->setPicYuvResi( m_apcPicYuvResi );
+  pcPic->setPicYuvPred( &m_picYuvPred );
+  pcPic->setPicYuvResi( &m_picYuvResi );
   rpcSlice->setSliceMode            ( m_pcCfg->getSliceMode()            );
   rpcSlice->setSliceArgument        ( m_pcCfg->getSliceArgument()        );
@@ -660,9 +619,9 @@
   if (m_pcCfg->getGOPSize() > 1)
   {
-    dFrameLambda = 0.68 * pow (2, (m_piRdPicQp[0]  - SHIFT_QP) / 3.0) * (pcSlice->isInterB()? 2 : 1);
+    dFrameLambda = 0.68 * pow (2, (m_viRdPicQp[0]  - SHIFT_QP) / 3.0) * (pcSlice->isInterB()? 2 : 1);
   }
   else
   {
-    dFrameLambda = 0.68 * pow (2, (m_piRdPicQp[0] - SHIFT_QP) / 3.0);
+    dFrameLambda = 0.68 * pow (2, (m_viRdPicQp[0] - SHIFT_QP) / 3.0);
   }
   m_pcRdCost      ->setFrameLambda(dFrameLambda);
@@ -671,9 +630,9 @@
   for ( UInt uiQpIdx = 0; uiQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; uiQpIdx++ )
   {
-    pcSlice       ->setSliceQp             ( m_piRdPicQp    [uiQpIdx] );
+    pcSlice       ->setSliceQp             ( m_viRdPicQp    [uiQpIdx] );
 #if ADAPTIVE_QP_SELECTION
-    pcSlice       ->setSliceQpBase         ( m_piRdPicQp    [uiQpIdx] );
-#endif
-    setUpLambda(pcSlice, m_pdRdPicLambda[uiQpIdx], m_piRdPicQp    [uiQpIdx]);
+    pcSlice       ->setSliceQpBase         ( m_viRdPicQp    [uiQpIdx] );
+#endif
+    setUpLambda(pcSlice, m_vdRdPicLambda[uiQpIdx], m_viRdPicQp    [uiQpIdx]);
 
     // try compress
@@ -699,9 +658,9 @@
 
   // set best values
-  pcSlice       ->setSliceQp             ( m_piRdPicQp    [uiQpIdxBest] );
+  pcSlice       ->setSliceQp             ( m_viRdPicQp    [uiQpIdxBest] );
 #if ADAPTIVE_QP_SELECTION
-  pcSlice       ->setSliceQpBase         ( m_piRdPicQp    [uiQpIdxBest] );
-#endif
-  setUpLambda(pcSlice, m_pdRdPicLambda[uiQpIdxBest], m_piRdPicQp    [uiQpIdxBest]);
+  pcSlice       ->setSliceQpBase         ( m_viRdPicQp    [uiQpIdxBest] );
+#endif
+  setUpLambda(pcSlice, m_vdRdPicLambda[uiQpIdxBest], m_viRdPicQp    [uiQpIdxBest]);
 }
 
Index: branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.h
===================================================================
--- branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.h	(revision 1538)
+++ branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.h	(revision 1540)
@@ -68,6 +68,6 @@
   // pictures
   TComList<TComPic*>*     m_pcListPic;                          ///< list of pictures
-  TComPicYuv*             m_apcPicYuvPred;                      ///< prediction picture buffer
-  TComPicYuv*             m_apcPicYuvResi;                      ///< residual picture buffer
+  TComPicYuv              m_picYuvPred;                         ///< prediction picture buffer
+  TComPicYuv              m_picYuvResi;                         ///< residual picture buffer
 
   // processing units
@@ -91,7 +91,7 @@
   UInt64                  m_uiPicDist;                          ///< total distortion for the picture
   Double                  m_dPicRdCost;                         ///< picture-level RD cost
-  Double*                 m_pdRdPicLambda;                      ///< array of lambda candidates
-  Double*                 m_pdRdPicQp;                          ///< array of picture QP candidates (double-type for lambda)
-  Int*                    m_piRdPicQp;                          ///< array of picture QP candidates (Int-type)
+  std::vector<Double>     m_vdRdPicLambda;                      ///< array of lambda candidates
+  std::vector<Double>     m_vdRdPicQp;                          ///< array of picture QP candidates (double-type for lambda)
+  std::vector<Int>        m_viRdPicQp;                          ///< array of picture QP candidates (Int-type)
   TEncRateCtrl*           m_pcRateCtrl;                         ///< Rate control manager
   UInt                    m_uiSliceIdx;
