Spectrogram memory usage

Dear everybody,

I am currently trying to create many spectrograms for several days of data. Each spectrograms should show 1 hour of data. For this, I created a script that basically runs a loop that cuts all the data into hourly pieces and creates a spectrogram for each piece.

However, I am running into troubles since the spectrogram function seems to have a strong memory usage. The main problem is, that apparently the data that is used internaly to calculate the spectrogram is not cleared from the memory once the spectrogram is finished and the file is saved. therefore, each time i calculate a new spectrogram the memory usage grows by a substantial ammount of megabytes and very quickly my computer runs out of memory. memory usage for ipython while running this loop is already at more than 10GB after a couple of minutes.

Is there any way to save memory while calculating those spectrograms? Any way to clear the spectrogram data from the memory once the calculation is done?

Thanks a lot in advance and best regards,

Florian Fuchs

Hi Florian,

I had issues like that with matplotlib at some point. It seems that it
keeps some references to the plots/data even after they are not
referenced in the script anymore (keeping the garbage collector from
doing its work).
I think there were posts and/or tickets about this. It should work fine
if you call matplotlib.pyplot.close() in your loop after you saved the
plot to explicitely tell matplotlib to get rid of the figure.

best,
Tobias

Very simple solution - thanks a lot :wink:

- Florian