imshow memory leak in pylab mode?

Furthermore,
deleting images from ax.images does not free memory :

In [1]: import gc

In [2]: import matplotlib.cbook as cbook

In [3]: data = ones((1500,1500,3))

In [4]: imshow data
------> imshow(data)

Out[4]: <matplotlib.image.AxesImage object at 0x1c57550>

In [5]: imshow data
------> imshow(data)

Out[5]: <matplotlib.image.AxesImage object at 0x1c442b0>

In [6]: imshow data
------> imshow(data)

Out[6]: <matplotlib.image.AxesImage object at 0x1400cd0>

In [7]: imshow data
------> imshow(data)

Out[7]: <matplotlib.image.AxesImage object at 0x1414cb0>

In [8]: ax =gca()

In [9]: ax.images

Out[9]:
[<matplotlib.image.AxesImage object at 0x1c57550>,
<matplotlib.image.AxesImage object at 0x1c442b0>,
<matplotlib.image.AxesImage object at 0x1400cd0>,
<matplotlib.image.AxesImage object at 0x1414cb0>]

In [10]: gc.collect()

Out[10]: 15

In [11]: cbook.report_memory()

Out[11]: 414588

In [12]: del ax.images[:-1]

In [13]: gc.collect()

Out[13]: 3

In [14]: cbook.report_memory()

Out[14]: 414600

···

On 2010-07-14 19:11:58 +0200, K.-Michael Aye said:

On 2010-07-14 18:51:26 +0200, K.-Michael Aye said:

On 2010-07-14 18:45:35 +0200, John Hunter said:

On Wed, Jul 14, 2010 at 11:38 AM, K.-Michael Aye >>> <kmichael.aye@...287...> wrote:

Out[12]: 1

In [13]: gc.collect()

Out[13]: 12

still not seeing a leak in your data -- you need to report_memory
after calling gc collect. Turn off hold, add an image, call collect,
report memory, the repeat several times, each time calling collect and
report memory, and report the results.

Was just following your example, you were nowhere calling collect.
Here is what you requested:

In [1]: import gc

In [2]: import matplotlib.cbook as cbook

In [3]: data = ones((1500,1500,3))

In [4]: hold(False)

In [5]: imshow(data)

Out[5]: <matplotlib.image.AxesImage object at 0x1c43e50>

In [6]: gc.collect()

Out[6]: 12

In [7]: cbook.report_memory()

Out[7]: 174540

In [8]: imshow(data)

Out[8]: <matplotlib.image.AxesImage object at 0x1c59e90>

In [9]: gc.collect()

Out[9]: 0

In [10]: cbook.report_memory()

Out[10]: 253400

In [11]: imshow(data)

Out[11]: <matplotlib.image.AxesImage object at 0x1c603b0>

In [12]: gc.collect()

Out[12]: 0

In [13]: cbook.report_memory()

Out[13]: 333360

In [14]: imshow(data)

Out[14]: <matplotlib.image.AxesImage object at 0x1c60410>

In [15]: gc.collect()

Out[15]: 0

In [16]: cbook.report_memory()

Out[16]: 413296

Here are the commands as macro form, for easy cut and paste into pylab:

import gc
import matplotlib.cbook as cbook
data = ones((1500,1500,3))
hold(False)
imshow(data)
gc.collect()
cbook.report_memory()
imshow(data)
gc.collect()
cbook.report_memory()
imshow(data)
gc.collect()
cbook.report_memory()
imshow(data)
gc.collect()
cbook.report_memory()

Out[12]: 1

In [13]: gc.collect()

Out[13]: 12

still not seeing a leak in your data -- you need to report_memory
after calling gc collect. Turn off hold, add an image, call collect,
report memory, the repeat several times, each time calling collect and
report memory, and report the results.

Was just following your example, you were nowhere calling collect.
Here is what you requested:

In [1]: import gc

In [2]: import matplotlib.cbook as cbook

In [3]: data = ones((1500,1500,3))

In [4]: hold(False)

In [5]: imshow(data)

Out[5]:<matplotlib.image.AxesImage object at 0x1c43e50>

In [6]: gc.collect()

Out[6]: 12

In [7]: cbook.report_memory()

Out[7]: 174540

In [8]: imshow(data)

Out[8]:<matplotlib.image.AxesImage object at 0x1c59e90>

In [9]: gc.collect()

Out[9]: 0

In [10]: cbook.report_memory()

Out[10]: 253400

In [11]: imshow(data)

Out[11]:<matplotlib.image.AxesImage object at 0x1c603b0>

In [12]: gc.collect()

Out[12]: 0

In [13]: cbook.report_memory()

Out[13]: 333360

In [14]: imshow(data)

Out[14]:<matplotlib.image.AxesImage object at 0x1c60410>

In [15]: gc.collect()

Out[15]: 0

In [16]: cbook.report_memory()

Out[16]: 413296

Here are the commands as macro form, for easy cut and paste into pylab:

import gc
import matplotlib.cbook as cbook
data = ones((1500,1500,3))
hold(False)
imshow(data)
gc.collect()
cbook.report_memory()
imshow(data)
gc.collect()
cbook.report_memory()
imshow(data)
gc.collect()
cbook.report_memory()
imshow(data)
gc.collect()
cbook.report_memory()

Furthermore,
deleting images from ax.images does not free memory :

Maybe because ipython is keeping a reference to every AxesImage object that you make...

Eric

···

On 07/16/2010 01:32 AM, K.-Michael Aye wrote:

On 2010-07-14 19:11:58 +0200, K.-Michael Aye said:

On 2010-07-14 18:51:26 +0200, K.-Michael Aye said:

On 2010-07-14 18:45:35 +0200, John Hunter said:

On Wed, Jul 14, 2010 at 11:38 AM, K.-Michael Aye >>>> <kmichael.aye@...287...> wrote:

In [1]: import gc

In [2]: import matplotlib.cbook as cbook

In [3]: data = ones((1500,1500,3))

In [4]: imshow data
------> imshow(data)

Out[4]:<matplotlib.image.AxesImage object at 0x1c57550>

In [5]: imshow data
------> imshow(data)

Out[5]:<matplotlib.image.AxesImage object at 0x1c442b0>

In [6]: imshow data
------> imshow(data)

Out[6]:<matplotlib.image.AxesImage object at 0x1400cd0>

In [7]: imshow data
------> imshow(data)

Out[7]:<matplotlib.image.AxesImage object at 0x1414cb0>

In [8]: ax =gca()

In [9]: ax.images

Out[9]:
[<matplotlib.image.AxesImage object at 0x1c57550>,
  <matplotlib.image.AxesImage object at 0x1c442b0>,
  <matplotlib.image.AxesImage object at 0x1400cd0>,
  <matplotlib.image.AxesImage object at 0x1414cb0>]

In [10]: gc.collect()

Out[10]: 15

In [11]: cbook.report_memory()

Out[11]: 414588

In [12]: del ax.images[:-1]

In [13]: gc.collect()

Out[13]: 3

In [14]: cbook.report_memory()

Out[14]: 414600