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.

RGB/rasterize not releasing memory properly

See original GitHub issue

ALL software version info

holoviews ‘1.13.4.post4+g8f7c67f70’ (current master)

Description of expected behavior and the observed behavior

I have an an image that I’m using hv.RGB and rasterize to render. Everytime I render the image, my memory usage for the python kernel increases incrementally. This incremental change matches with what tracemalloc tells me the image construction is consuming. Essentially, the memory allocated for the image is never released. I have to restart my kernel to release the memory.

Complete, minimal, self-contained example code that reproduces the issue

A test image can be downloaded from unsplash, for example this one. Be sure to get the original size. Or you can immediately download the file if you trust me enough to start the download directly 😃

This bit of code will tell us that we need about 48 MB of memory to run this

from PIL import Image
import tracemalloc
import holoviews as hv
hv.extension('bokeh')

path = 'shifaaz-shamoon-ikVBaapsTPg-unsplash.jpg'

tracemalloc.start()
with open(path, 'rb') as f:
    image = np.array(Image.open(f))
img = hv.RGB(image)    
rasterize(img)
snapshot = tracemalloc.take_snapshot()
top_stats = snapshot.statistics('lineno')
print("[ Top 10 ]")
for stat in top_stats[:10]:
    print(stat)

Now, if you repeatedly call the following code:

with open(path, 'rb') as f:
    image = np.array(Image.open(f))
img = hv.RGB(image)    
rasterize(img)

You’ll see that every time it’s run (I’m using jupyter to visualize), the memory consumption on your machine increases by 48 MB.

If you remove the rasterize(img) step, you won’t see any memory increase. I suppose this would be expected since it isn’t rendered, the object isn’t populated in the same way?

Also, if only call the PIL portion like this:

with open(path, 'rb') as f:
    image = np.array(Image.open(f))

You can see that this bit is properly releasing memory. So it seems to be and issue with the hv.RGB object.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
philippjfrcommented, Nov 30, 2020

I no longer believe this to be a real issue, we have been running an application which uses rasterize/datashade for over a month now without leaking memory.

0reactions
jlstevenscommented, Oct 5, 2020

I’ll assign this to the next milestone (from v1.13.x) - if it turns out to be a difficult, fundamental problem to solve we can bump it back

Read more comments on GitHub >

github_iconTop Results From Across the Web

Windows 10 not releasing standby memory when required.
My system has 16GB of RAM and a max pagefile of 1000MB. The standby memory cache stays around 7GB even when my commit...
Read more >
Not Releasing Memory · Issue #48 · proxb/PoshRSJob - GitHub
Hi Boe, Give these the following a try in a new PowerShell window and use task manager to keep an eye on the...
Read more >
Chapter 12 Release Memory | Best Coding Practices for R
R has a function by name gc to run a garbage collector and release the memory that is not needed anymore. It's useful...
Read more >
c++ - _bstr_t memory leak - Stack Overflow
I have a c++ code. But it is not releasing memory properly. Tell me where I am wrong, here ...
Read more >
HD54578: SERVER PROCESS DOESN'T RELEASE ... - IBM
Server process doesn't release memory when client closed viewer. ... there is not reduction in memory consumption usage, it appears to be a...
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