question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory usage is growing with the iterations

See original GitHub issue

Describe the bug

Memory usage is growing with iterations.

To Reproduce

It should work with any kind of audio file but I can send the considered file if needed.

import librosa
import matplotlib.pyplot as plt
import os
import psutil

def foo():
    y, sr = librosa.load("clip_04.wav", sr=22050, offset=600, duration=60)
    spec_mag = abs(librosa.stft(y, n_fft=2048, hop_length=1024))
    spec_db = librosa.amplitude_to_db(spec_mag)
    return 42

def main():

    process = psutil.Process(os.getpid())

    array = []

    for i in range(100):
        print(i)
        foo()
        m = int(process.memory_info().rss / 1024**2)
        array.append(m)

    plt.figure()
    plt.plot(array)
    plt.xlabel('iterations')
    plt.ylabel('MB')
    plt.show()

if __name__ == '__main__':
    main()

Expected behavior

Memory usage should be constant.

Screenshots

Screenshot 2021-02-21 at 15 47 46

Software versions

Darwin-19.6.0-x86_64-i386-64bit
Python 3.7.9 (default, Aug 31 2020, 07:22:35) 
[Clang 10.0.0 ]
NumPy 1.19.5
SciPy 1.5.2
librosa 0.8.0
INSTALLED VERSIONS
------------------
python: 3.7.9 (default, Aug 31 2020, 07:22:35) 
[Clang 10.0.0 ]

librosa: 0.8.0

audioread: 2.1.8
numpy: 1.19.5
scipy: 1.5.2
sklearn: 0.23.2
joblib: 0.17.0
decorator: 4.4.2
soundfile: 0.10.2
resampy: 0.2.2
numba: 0.51.2

numpydoc: None
sphinx: None
sphinx_rtd_theme: None
sphinxcontrib.versioning: None
sphinx-gallery: None
pytest: None
pytest-mpl: None
pytest-cov: None
matplotlib: 3.2.2
presets: None

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
vincent-powdercommented, Feb 23, 2021

I’ll try to use soundfile.read() with offset and duration constraints. I’ll post here the results of my findings. Thanks again for helping me on this.

0reactions
vincent-powdercommented, Mar 1, 2021

Hello @bmcfee, I’ve used the code you’ve sent to read the wav file and here are my findings:

  • If I read the entire wav file, the memory usage is constant
  • If I use an offset, the memory usage is constant
  • If I use a custom duration, the memory usage increases As you pointed out, the problem is probably not related to Librosa. Thanks again for investigating.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why my memory keeps increasing at every iteration? - vision
If you are seeing an increase in the memory usage in each iteration, check if you are storing any tensors, which might be...
Read more >
PHP memory usage in For loop keeps growing - Stack Overflow
Increasing memory usage in PHP is normal. unsetting a variable doesn't immediately free up the memory it was taking, it simply marks it...
Read more >
Hunting Down Memory Issues In Ruby: A Definitive Guide
What may not be intuitive is why memory usage continues to grow after the first iteration. After all, it built a big array,...
Read more >
How to Write Memory Efficient Loops in Python - Medium
In python, when you build a list of numbers, images, files, or any other object that you want to iterate through, you're essentially...
Read more >
VI Memory Usage - NI - National Instruments
Functions that generate data take care of allocating the storage for that data. When data is no longer being used, the associated memory...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found