CoreWebView2SharedBuffer.Close Method

Definition

public void Close ();
member this.Close : unit -> unit
Public Sub Close ()

Remarks

The application should call Close or Dispose() when no access to the buffer is needed any more, to ensure that the underlying resources are released timely even if the shared buffer object itself is not released due to some leaked reference. After the shared buffer is closed, the buffer address and file mapping handle previously obtained becomes invalid and cannot be used anymore. Properties of the object will also be unaccessible. Operations like Read or Write on the stream objects returned from OpenStream() will also fail. PostSharedBufferToScript(CoreWebView2SharedBuffer, CoreWebView2SharedBufferAccess, String) will also fail. The failures will be represented as COMException with error code of RO_E_CLOSED.

The script code should call chrome.webview.releaseBuffer with the shared buffer as the parameter to release underlying resources as soon as it does not need access the shared buffer any more. When script tries to access the buffer after calling chrome.webview.releaseBuffer, JavaScript TypeError exception will be raised complaining about accessing a detached ArrayBuffer, the same exception when trying to access a transferred ArrayBuffer.

Closing the buffer object on native side doesn't impact access from Script and releasing the buffer from script doesn't impact access to the buffer from native side. The underlying shared memory will be released by the OS when both native and script side release the buffer.

Applies to