Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak when repeatedly using the same Output widget #2304

Open
spott opened this issue Jan 29, 2019 · 3 comments
Open

Memory Leak when repeatedly using the same Output widget #2304

spott opened this issue Jan 29, 2019 · 3 comments

Comments

@spott
Copy link

spott commented Jan 29, 2019

I'm pretty sure I'm running into #1345, but I don't know how to apply the fix, so I'm creating a new issue.

I'm using a widget to show a new bokeh plot when I hit "next". A simple version of the problem:

from bokeh.plotting import figure, output_notebook, show

import ipywidgets as widgets
from ipywidgets import Layout,Box
output_notebook()
import numpy as np

def plot_sample_bokeh(i):
    f = figure(title="test")
    f.line(np.arange(100), np.random.randn(100))
    
    show(f)

to_annotate = np.arange(100)
cur_index = 0

def display_img_widget(i):
    with out_widget:
        plot_sample_bokeh(i)
        
def on_button_click(b):
    global to_annotate, cur_index
    cur_id = to_annotate[cur_index]
    
    cur_index += 1
    
    if cur_index == len(to_annotate):
        print('End of collection')
        return
    out_widget.clear_output(wait=True)
    display_img_widget(to_annotate[cur_index])

a_button = widgets.Button(description='next', button_style='primary')
a_button.on_click(on_button_click)

out_widget = widgets.Output(width=1100, height=600)

display_img_widget(to_annotate[0])

form_item_layout = Layout(
    display='flex',
    flex_flow='row',
    justify_content='flex-start', width='100%')

form = VBox([a_button, out_widget], layout=form_item_layout)

form

If this is run in a Jupyter notebook, and the 'next' button is repeatedly clicked, you can watch the memory usage of the webpage climb in chrome. Restarting the kernel doesn't reduce the memory usage of the page and eventually, the page will just crash.

How do I go about fixing this?

@nickpollari
Copy link

nickpollari commented Feb 4, 2019

Actually just ran into this issue myself yesterday. I'm looking at ways of modifying the structure of my code to try and reduce the memory usage and overhead. I plan to try and update the data in my plot rather than creating a whole new figure each time. Do you think this would help you @spott ?

@jasongrout might have some good input here

@spott
Copy link
Author

spott commented Feb 4, 2019

@nickpollari Yes, I think it would.

It appears that my particular problem is likely related to Bokeh itself, rather than ipywidgets, though I'm not sure if it is something in Bokeh that needs to be deleting references, or something else.

@fcollonval
Copy link
Contributor

Hey @nickpollari and @spott
We encountered than error with Bokeh. And therefore we tried plotly. Plotly does not have a memory leak. So this is definitely related to Bokeh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants