Skip to content

fix: [Widget Image] Remove oldurl string check since it's always a string and prevent the ObjectURL cleaning resulting in a memory leak. #3171

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

Merged

Conversation

joseph2rs
Copy link

See #3170

…ring and prevent the ObjectURL cleaning resulting in a memory leak.
@github-actions
Copy link

Binder 👈 Launch a binder notebook on branch joseph2rs/ipywidgets/widget_image_fix_revoke_object_url

@jasongrout
Copy link
Member

jasongrout commented Mar 25, 2021

Thanks!

This check was added in 1b16391 (#1676) to distinguish between that src being an external url or an internal object url.

However, it looks like step 2 of the revoking process checks to see if the url has scheme blob:, so I think we can call revoke on any URL (including external URLs) and it will silently return if the url is not a blob url. Indeed, the standard says:

Note: This means that rather than throwing some kind of error, attempting to revoke a URL that isn’t registered will silently fail. User agents might display a message on the error console if this happens.

I see that we have this same logic in the video and audio widgets. Can you fix it in those files too?

@jasongrout
Copy link
Member

FYI, on current firefox and chrome, URL.revokeObjectURL('http://google.com') just silently returns without an error message, so I think we don't even have the error message the standard warns may happen.

@jasongrout
Copy link
Member

Other places are at

if (oldurl && typeof oldurl !== 'string') {
URL.revokeObjectURL(oldurl);
}
and
if (oldurl && typeof oldurl !== 'string') {
URL.revokeObjectURL(oldurl);
}

…Widgets, since revokeObjectURL silently return on non-blob urls.
@joseph2rs
Copy link
Author

FYI i removed also the check on oldurl since passing undefined or null fail silently.

@jasongrout
Copy link
Member

FYI i removed also the check on oldurl since passing undefined or null fail silently.

Reading the standard, we aren't guaranteed passing in undefined or null will always fail silently, just that a url that is not an object url will. In the standard, the first step is to parse the url, and the parsing standard seems to really want a string.

Can you put back in the oldurl test so we're following the standard more closely? That will make it more certain it will work across browsers, at least ones that implement the spec as written.

@jasongrout
Copy link
Member

Thanks!

@jasongrout jasongrout merged commit 24628f0 into jupyter-widgets:master Mar 25, 2021
@jtpio jtpio added this to the 8.0 milestone Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants