diff --git a/src/algorithms/DPAdaptiveMedian.cpp b/src/algorithms/DPAdaptiveMedian.cpp
index 5c34d3f538d2ba81c20634b7dc5a27c7da8b1c80..45d40449d5379a0912425883dc66058072fc3a40 100644
--- a/src/algorithms/DPAdaptiveMedian.cpp
+++ b/src/algorithms/DPAdaptiveMedian.cpp
@@ -61,6 +61,7 @@ void DPAdaptiveMedian::process(const cv::Mat &img_input, cv::Mat &img_output, cv
 
   img_foreground.copyTo(img_output);
   img_background.copyTo(img_bgmodel);
+  frame_data.ReleaseImage();
 
   firstTime = false;
   frameNumber++;
diff --git a/src/algorithms/DPEigenbackground.cpp b/src/algorithms/DPEigenbackground.cpp
index 9ddc1b92245f3c0c6a1582ce8f70009cd8f0f232..9442be1eb81c9eb4188cc13b043cec66ba20217c 100644
--- a/src/algorithms/DPEigenbackground.cpp
+++ b/src/algorithms/DPEigenbackground.cpp
@@ -61,6 +61,7 @@ void DPEigenbackground::process(const cv::Mat &img_input, cv::Mat &img_output, c
 
   img_foreground.copyTo(img_output);
   img_background.copyTo(img_bgmodel);
+  frame_data.ReleaseImage();
 
   firstTime = false;
   frameNumber++;
diff --git a/src/algorithms/DPGrimsonGMM.cpp b/src/algorithms/DPGrimsonGMM.cpp
index d9d8e4c5adb8f41112beae664cba54498f9e9a1b..ff3e16d3fd792965bb2887fd6d821be61c5ae012 100644
--- a/src/algorithms/DPGrimsonGMM.cpp
+++ b/src/algorithms/DPGrimsonGMM.cpp
@@ -60,6 +60,7 @@ void DPGrimsonGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Ma
 
   img_foreground.copyTo(img_output);
   img_background.copyTo(img_bgmodel);
+  frame_data.ReleaseImage();
 
   firstTime = false;
   frameNumber++;
diff --git a/src/algorithms/DPMean.cpp b/src/algorithms/DPMean.cpp
index cc106faa6c0e2d36e1f1520b991c1e0385153f4b..caa17e401547a003a3af7b19e0992c5820bfd91f 100644
--- a/src/algorithms/DPMean.cpp
+++ b/src/algorithms/DPMean.cpp
@@ -60,6 +60,7 @@ void DPMean::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &img
 
   img_foreground.copyTo(img_output);
   img_background.copyTo(img_bgmodel);
+  frame_data.ReleaseImage();
 
   firstTime = false;
   frameNumber++;
diff --git a/src/algorithms/DPPratiMediod.cpp b/src/algorithms/DPPratiMediod.cpp
index 17c9f98505be4c88c4b2dd01c902e0c8c4e3796e..c7bfada1e690a4ae94077fb8d011d6d1f8ebe447 100644
--- a/src/algorithms/DPPratiMediod.cpp
+++ b/src/algorithms/DPPratiMediod.cpp
@@ -61,6 +61,7 @@ void DPPratiMediod::process(const cv::Mat &img_input, cv::Mat &img_output, cv::M
 
   img_foreground.copyTo(img_output);
   img_background.copyTo(img_bgmodel);
+  frame_data.ReleaseImage();
 
   firstTime = false;
   frameNumber++;
diff --git a/src/algorithms/DPTexture.cpp b/src/algorithms/DPTexture.cpp
index ec5dd3e8b3d170b0024cd132001034deb6a4ca9a..920baf694e40e8b1ed77c3f3b8fc28eb4fbd0573 100644
--- a/src/algorithms/DPTexture.cpp
+++ b/src/algorithms/DPTexture.cpp
@@ -32,15 +32,15 @@ void DPTexture::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
   IplImage _frame = cvIplImage(img_input);
   frame = cvCloneImage(&_frame);
 
-  if (firstTime) {
-    width = img_input.size().width;
-    height = img_input.size().height;
-    size = width * height;
+  width = img_input.size().width;
+  height = img_input.size().height;
+  size = width * height;
 
-    // input image
-    image = cvCreateImage(cvSize(width, height), 8, 3);
-    cvCopy(frame, image.Ptr());
+  // input image
+  image = cvCreateImage(cvSize(width, height), 8, 3);
+  cvCopy(frame, image.Ptr());
 
+  if (firstTime) {
     // foreground masks
     fgMask = cvCreateImage(cvSize(width, height), 8, 1);
     tempMask = cvCreateImage(cvSize(width, height), 8, 1);
@@ -74,13 +74,13 @@ void DPTexture::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
     //erodeElement = cvCreateStructuringElementEx(3, 3, 1, 1,	CV_SHAPE_RECT);
     firstTime = false;
   }
-
-  cvCopy(frame, image.Ptr());
-
-  // perform background subtraction
-  bgs.LBP(image, texture);
-  bgs.Histogram(texture, curTextureHist);
-  bgs.BgsCompare(bgModel, curTextureHist, modeArray, dp::THRESHOLD, fgMask);
+  else {
+    // cvCopy(frame, image.Ptr());
+    // perform background subtraction
+    bgs.LBP(image, texture);
+    bgs.Histogram(texture, curTextureHist);
+    bgs.BgsCompare(bgModel, curTextureHist, modeArray, dp::THRESHOLD, fgMask);
+  }
 
   //if(enableFiltering)
   //{
@@ -113,6 +113,10 @@ void DPTexture::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &
 
   // update background subtraction
   bgs.UpdateModel(fgMask, bgModel, curTextureHist, modeArray);
+
+  // free memory
+  image.ReleaseImage();
+  cvReleaseImage(&frame);
 }
 
 void DPTexture::save_config(cv::FileStorage &fs) {
diff --git a/src/algorithms/DPWrenGA.cpp b/src/algorithms/DPWrenGA.cpp
index 05b35a6803d527d53701bdcd95c59d485e88cfb5..bb92f2f5bb3a5cae5faf8e0e97ab13ebdb632d32 100644
--- a/src/algorithms/DPWrenGA.cpp
+++ b/src/algorithms/DPWrenGA.cpp
@@ -59,6 +59,7 @@ void DPWrenGA::process(const cv::Mat &img_input, cv::Mat &img_output, cv::Mat &i
 
   img_foreground.copyTo(img_output);
   img_background.copyTo(img_bgmodel);
+  frame_data.ReleaseImage();
 
   firstTime = false;
   frameNumber++;
diff --git a/src/algorithms/DPZivkovicAGMM.cpp b/src/algorithms/DPZivkovicAGMM.cpp
index a087b4fbe7483f6ecc82a92290b23ea1910bac81..9ba35654fb9a72545f8da13af9f5febb2e2b0238 100644
--- a/src/algorithms/DPZivkovicAGMM.cpp
+++ b/src/algorithms/DPZivkovicAGMM.cpp
@@ -59,6 +59,7 @@ void DPZivkovicAGMM::process(const cv::Mat &img_input, cv::Mat &img_output, cv::
 
   img_foreground.copyTo(img_output);
   img_background.copyTo(img_bgmodel);
+  frame_data.ReleaseImage();
 
   firstTime = false;
   frameNumber++;