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

Add the close() method to the ImageBitmap interface #1078

Merged
merged 1 commit into from
Apr 21, 2016
Merged

Add the close() method to the ImageBitmap interface #1078

merged 1 commit into from
Apr 21, 2016

Conversation

junov
Copy link
Member

@junov junov commented Apr 20, 2016

This method releases the graphics resources held by an
ImageBitmap object.
This is part of the larger OffscreenCanvas feature proposal:
https://wiki.whatwg.org/wiki/OffscreenCanvas
The only known implementation at this time is in Firefox:
https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap/close

<p>The <dfn><code data-x="dom-ImageBitmap-width">width</code></dfn> attribute's getter must run
these steps:</p>

<ol>
<li><p>If this <code>ImageBitmap</code> object's [[<span>Detached</span>]] internal slot's
<li><p>If <b>this</b>'s [[<span>Detached</span>]] internal slot's
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by editorial tweak.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current form is actually preferable, at least for now and in HTML. this technically only has meaning, currently, in ES-style algorithms, so we've been trying to use "this X object" or "this element" instead.

Eventually we may have Web IDL define the this keyword to mean "the Web IDL object corresponding to the JavaScript object given by this" or something like that.

@domenic
Copy link
Member

domenic commented Apr 20, 2016

I assume Chrome is interested :). If so, we have two vendors, so LGTM except without the drive-by editorial tweak.

@domenic domenic added addition/proposal New features or enhancements topic: canvas and removed topic: canvas labels Apr 20, 2016
This method releases the graphics resources held by an
ImageBitmap object.
This is part of the larger OffscreenCanvas feature proposal:
https://wiki.whatwg.org/wiki/OffscreenCanvas
This is already implemented and shipping in Firefox 46:
https://developer.mozilla.org/en-US/docs/Web/API/ImageBitmap/close
It is implemented and will ship soon in Chrome.
@junov
Copy link
Member Author

junov commented Apr 21, 2016

Done.

@annevk annevk merged commit 2b85a3f into whatwg:master Apr 21, 2016
@annevk
Copy link
Member

annevk commented Apr 21, 2016

(I was thinking that unsetting the image data does not need to be done since it's not observable, but apparently we already do that elsewhere. Perhaps something we can clean up at some point.)

It is true that the effect of unsetting is not observable in JS, but it is observable for the user. One of the purposes of this API is to force an immediate release of resources instead of waiting for the ImageBitmap to be garbage collected. So being explicit about makes some sense IMHO. From a practical standpoint there are several justifications for this:

  1. The ImageBitmap object may be holding on to GPU resources (depending on the implementation) and GPU resource strain is typically not a garbage collection trigger for the JavaScript heap. Solving this problem in the browser implementation is extremely difficult because GPU APIs offer poor visibility into resource availability.
  2. Bitmap resource churn in RAM can cause frequent garbage collections, which may result in animation hiccups. This API gives app devs more explicit control to mitigate that issue.
  3. Proactive releasing keeps the process size under control, which is good for system-wide performance.

@junov junov deleted the imagebitmapclose branch July 7, 2022 16:08
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements
Development

Successfully merging this pull request may close these issues.

3 participants