diff --git a/pingmapper/class_portstarObj.py b/pingmapper/class_portstarObj.py index 1493581..09ed8b3 100644 --- a/pingmapper/class_portstarObj.py +++ b/pingmapper/class_portstarObj.py @@ -1265,6 +1265,9 @@ def _depthZheng(self,i,tileFile): del maxDepths, minDepths, avgDepths, Wp, portDepPixCrop, starDepPixCrop del portDepPix, starDepPix del model, self.bedpickModel ######## Not sure about this one... + + # Force garbage collection to free memory + gc.collect() # return #self return portDepPixFinal, starDepPixFinal, i diff --git a/pingmapper/class_sonObj.py b/pingmapper/class_sonObj.py index 89566fb..8f95415 100644 --- a/pingmapper/class_sonObj.py +++ b/pingmapper/class_sonObj.py @@ -1192,6 +1192,10 @@ def _writeTiles(self, projName = os.path.split(self.projDir)[-1] #to append project name to filename imsave(os.path.join(outDir, projName+'_'+imgOutPrefix+'_'+channel+'_'+addZero+str(k)+tileFile), data, check_contrast=False) + # Clean up temporary data array to free memory + del data + gc.collect() + return def _writeTilesPlot(self, @@ -1253,6 +1257,9 @@ def _writeTilesPlot(self, colored_data = plt.cm.get_cmap(self.sonogram_colorMap)(norm_data) colored_data = (colored_data[:, :, :3] * 255).astype('uint8') data = colored_data + + # Clean up temporary arrays + del norm_data, colored_data # imsave(outfile, data) @@ -1262,7 +1269,10 @@ def _writeTilesPlot(self, # imsave(outfile, data, check_contrast=False) imsave(outfile, data, check_contrast=False) - + + # Clean up temporary data array to free memory + del data + gc.collect() return @@ -1549,6 +1559,10 @@ def resize_to_pingMax(img, cropMax): win += to_stride + # Clean up large arrays to free memory + del a_img, b_img, movWin + gc.collect() + return diff --git a/pingmapper/class_sonObj_nadirgaptest.py b/pingmapper/class_sonObj_nadirgaptest.py index 54e8b41..fd32750 100644 --- a/pingmapper/class_sonObj_nadirgaptest.py +++ b/pingmapper/class_sonObj_nadirgaptest.py @@ -1136,6 +1136,10 @@ def _writeTiles(self, projName = os.path.split(self.projDir)[-1] #to append project name to filename imsave(os.path.join(outDir, projName+'_'+imgOutPrefix+'_'+channel+'_'+addZero+str(k)+tileFile), data, check_contrast=False) + # Clean up temporary data array to free memory + del data + gc.collect() + return def _writeTilesPlot(self, @@ -1197,6 +1201,9 @@ def _writeTilesPlot(self, colored_data = plt.cm.get_cmap(self.sonogram_colorMap)(norm_data) colored_data = (colored_data[:, :, :3] * 255).astype('uint8') data = colored_data + + # Clean up temporary arrays + del norm_data, colored_data # imsave(outfile, data) @@ -1206,7 +1213,10 @@ def _writeTilesPlot(self, # imsave(outfile, data, check_contrast=False) imsave(outfile, data, check_contrast=False) - + + # Clean up temporary data array to free memory + del data + gc.collect() return @@ -1460,6 +1470,10 @@ def resize_to_pingMax(img, cropMax): win += to_stride + # Clean up large arrays to free memory + del a_img, b_img, movWin + gc.collect() + return