views:

53

answers:

1

I think I may have misunderstood something here... But here goes.

I'm using the psd method in matplotlib inside a loop, I'm not making it plot anything, I just want the numerical result, so:

import pylab as pyl
...
psdResults = pyl.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman)

But that's being looped 36 times every time I run the function it's in.

I'm getting a slow memory leak when I run my program over time, so used 'heapy' to monitor this, and every time I run the function, it adds 36 to these 3 heaps:

dict matplotlib.line.Line26
dict matplotlib.transforms.CompositeAffine2D
dict matplotlib.path.Path

I can only conclude that each time I use the psd method it merely adds it to some dictionary somewhere, whereas I want to effectively wipe the memory - i.e. reset pylab each loop so it doesn't store anything.

I could be misinterpreting heapy but it seems pretty clear that pylab is just growing each loop even though I only want to use it's psd method, I don't want it saving the results anywhere itself !

Cheers

+2  A: 

Try this:

from matplotlib import mlab
psdResults = mlab.psd(inputData, NFFT=512, Fs=sampleRate, window=blackman)

Does that improve the situation?

Steve
Excellent, yes it has...That has also highlighted the difference in import types too. Thanks alot! Just got to fix the other memory leaks now..!
Duncan Tait
In fact that's actually fixed all of them. Awesome.
Duncan Tait
Wow, great! If you use ipython, the command `pylab.psd??` will show you the source code. From there, I traced `psd` back to `Axes` and then `mlab`. This is how ipython introspection can help determine what is really going on.
Steve