Skip to main content
Notice removed Canonical answer required by g3kk0
Bounty Ended with bobthechemist's answer chosen by g3kk0
added 540 characters in body
Source Link
g3kk0
  • 3.3k
  • 19
  • 37

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I broke it down which took me quite a time and had to figure out that the problem occured in a simple function that includes a GaussianFilter in Block. The following simple code increases the memory each time I execute it and I can't figure out how to stop this:

image = Import["ExampleData/CTengine.tiff", "Image3D"]; oldMem = MemoryInUse[]; GaussianFilter[image, 1]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6569

Meaning that the consumed RAM increases by about 58 MB when the filter is applied even though nothing is returned. I checked for the data type that is produced by the GaussianFilter. The data type changes from Byte to Real32. I know that Mathematica stores output internally but nothing is returned. Especially, I don't understand why the memory is never freed even if I put the stuff into scoping structures like Block. By the way, setting $HistoryLength$HistoryLength to 0 doesn't help either.

ImageType@image ImageType@GaussianFilter[image, 1] 

Byte

Real32

fun[image_] := Block[ {}, GaussianFilter[image, 1]; ]; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

$HistoryLength = 0; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

The same problem also occurs when using Map:

oldMem = MemoryInUse[]; $HistoryLength = 0; Map[GaussianFilter[img3d, 1] &, Range[1, 10]]; oldMem/1000/1000 // N MemoryInUse[]/1000/1000 // N (MemoryInUse[] - oldMem)/1000/1000 // N 

28.9377

620.817

591.878

Without saving anything into a variable, the memory has increased by 590 MB. Besides, setting $HistoryLength to zero shows no effect. I also tried to Clear In and Out, again with no effect.

Unprotect[In, Out] Clear[In, Out] 

System specifictation

  • OS: Windows 7 Professional, Service Pack 1 (64-bit)
  • Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)
  • Installed memory: 96 GB
  • Mathematica 10.0.1

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I broke it down which took me quite a time and had to figure out that the problem occured in a simple function that includes a GaussianFilter in Block. The following simple code increases the memory each time I execute it and I can't figure out how to stop this:

image = Import["ExampleData/CTengine.tiff", "Image3D"]; oldMem = MemoryInUse[]; GaussianFilter[image, 1]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6569

Meaning that the consumed RAM increases by about 58 MB when the filter is applied even though nothing is returned. I checked for the data type that is produced by the GaussianFilter. The data type changes from Byte to Real32. I know that Mathematica stores output internally but nothing is returned. Especially, I don't understand why the memory is never freed even if I put the stuff into scoping structures like Block. By the way, setting $HistoryLength to 0 doesn't help either.

ImageType@image ImageType@GaussianFilter[image, 1] 

Byte

Real32

fun[image_] := Block[ {}, GaussianFilter[image, 1]; ]; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

$HistoryLength = 0; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

System specifictation

  • OS: Windows 7 Professional, Service Pack 1 (64-bit)
  • Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)
  • Installed memory: 96 GB
  • Mathematica 10.0.1

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I broke it down which took me quite a time and had to figure out that the problem occured in a simple function that includes a GaussianFilter in Block. The following simple code increases the memory each time I execute it and I can't figure out how to stop this:

image = Import["ExampleData/CTengine.tiff", "Image3D"]; oldMem = MemoryInUse[]; GaussianFilter[image, 1]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6569

Meaning that the consumed RAM increases by about 58 MB when the filter is applied even though nothing is returned. I checked for the data type that is produced by the GaussianFilter. The data type changes from Byte to Real32. I know that Mathematica stores output internally but nothing is returned. Especially, I don't understand why the memory is never freed even if I put the stuff into scoping structures like Block. By the way, setting $HistoryLength to 0 doesn't help either.

ImageType@image ImageType@GaussianFilter[image, 1] 

Byte

Real32

fun[image_] := Block[ {}, GaussianFilter[image, 1]; ]; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

$HistoryLength = 0; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

The same problem also occurs when using Map:

oldMem = MemoryInUse[]; $HistoryLength = 0; Map[GaussianFilter[img3d, 1] &, Range[1, 10]]; oldMem/1000/1000 // N MemoryInUse[]/1000/1000 // N (MemoryInUse[] - oldMem)/1000/1000 // N 

28.9377

620.817

591.878

Without saving anything into a variable, the memory has increased by 590 MB. Besides, setting $HistoryLength to zero shows no effect. I also tried to Clear In and Out, again with no effect.

Unprotect[In, Out] Clear[In, Out] 

System specifictation

  • OS: Windows 7 Professional, Service Pack 1 (64-bit)
  • Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)
  • Installed memory: 96 GB
  • Mathematica 10.0.1
Notice added Canonical answer required by g3kk0
Bounty Started worth 100 reputation by g3kk0
Tweeted twitter.com/#!/StackMma/status/532004598806880256
added 188 characters in body
Source Link
g3kk0
  • 3.3k
  • 19
  • 37

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I broke it down which took me quite a time and had to figure out that the problem occured in a simple function that includes a GaussianFilter in Block. The following simple code increases the memory each time I execute it and I can't figure out how to stop this:

image = Import["ExampleData/CTengine.tiff", "Image3D"]; oldMem = MemoryInUse[]; GaussianFilter[image, 1]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6569

Meaning that the consumed RAM increases by about 58 MB when the filter is applied even though nothing is returned. I checked for the data type that is produced by the GaussianFilterGaussianFilter. The data type changes from Byte to Real32. I know that Mathematica stores output internally but nothing is returned. Especially, I don't understand why the memory is never freed even if I put the stuff into scoping structures like Block. By the way, setting $HistoryLength to 0 doesn't help either.

ImageType@image ImageType@GaussianFilter[image, 1] 

Byte

Real32

fun[image_] := Block[ {}, GaussianFilter[image, 1]; ];   oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

$HistoryLength = 0; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

System specifictation

  • OS: Windows 7 Professional, Service Pack 1 (64-bit)
  • Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)
  • Installed memory: 96 GB
  • Mathematica 10.0.1

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I broke it down which took me quite a time and had to figure out that the problem occured in a simple function that includes a GaussianFilter in Block. The following simple code increases the memory each time I execute it and I can't figure out how to stop this:

image = Import["ExampleData/CTengine.tiff", "Image3D"]; oldMem = MemoryInUse[]; GaussianFilter[image, 1]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6569

Meaning that the consumed RAM increases by about 58 MB when the filter is applied even though nothing is returned. I checked for the data type that is produced by the GaussianFilter. The data type changes from Byte to Real32. I know that Mathematica stores output internally but nothing is returned. Especially, I don't understand why the memory is never freed even if I put the stuff into scoping structures like Block.

ImageType@image ImageType@GaussianFilter[image, 1] 

Byte

Real32

fun[image_] := Block[ {}, GaussianFilter[image, 1]; ]; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

System specifictation

  • OS: Windows 7 Professional, Service Pack 1 (64-bit)
  • Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)
  • Installed memory: 96 GB
  • Mathematica 10.0.1

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I broke it down which took me quite a time and had to figure out that the problem occured in a simple function that includes a GaussianFilter in Block. The following simple code increases the memory each time I execute it and I can't figure out how to stop this:

image = Import["ExampleData/CTengine.tiff", "Image3D"]; oldMem = MemoryInUse[]; GaussianFilter[image, 1]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6569

Meaning that the consumed RAM increases by about 58 MB when the filter is applied even though nothing is returned. I checked for the data type that is produced by the GaussianFilter. The data type changes from Byte to Real32. I know that Mathematica stores output internally but nothing is returned. Especially, I don't understand why the memory is never freed even if I put the stuff into scoping structures like Block. By the way, setting $HistoryLength to 0 doesn't help either.

ImageType@image ImageType@GaussianFilter[image, 1] 

Byte

Real32

fun[image_] := Block[ {}, GaussianFilter[image, 1]; ];   oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

$HistoryLength = 0; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

System specifictation

  • OS: Windows 7 Professional, Service Pack 1 (64-bit)
  • Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)
  • Installed memory: 96 GB
  • Mathematica 10.0.1
Source Link
g3kk0
  • 3.3k
  • 19
  • 37

Why does this line increase the consumed memory?

Probably this is a simple question, however I really don't understand this behavior in Mathematica. It particularly leads to a memory leak in a huge program I have to do processing of 3D images. I broke it down which took me quite a time and had to figure out that the problem occured in a simple function that includes a GaussianFilter in Block. The following simple code increases the memory each time I execute it and I can't figure out how to stop this:

image = Import["ExampleData/CTengine.tiff", "Image3D"]; oldMem = MemoryInUse[]; GaussianFilter[image, 1]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6569

Meaning that the consumed RAM increases by about 58 MB when the filter is applied even though nothing is returned. I checked for the data type that is produced by the GaussianFilter. The data type changes from Byte to Real32. I know that Mathematica stores output internally but nothing is returned. Especially, I don't understand why the memory is never freed even if I put the stuff into scoping structures like Block.

ImageType@image ImageType@GaussianFilter[image, 1] 

Byte

Real32

fun[image_] := Block[ {}, GaussianFilter[image, 1]; ]; oldMem = MemoryInUse[]; fun[image]; N[(MemoryInUse[] - oldMem)/1000/1000] 

58.6571

System specifictation

  • OS: Windows 7 Professional, Service Pack 1 (64-bit)
  • Processor: Intel Xeon CPU E5630 @ 2.53 GHz (2 Processors)
  • Installed memory: 96 GB
  • Mathematica 10.0.1