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

cache not release #43

Open
shixued opened this issue Jun 20, 2024 · 1 comment
Open

cache not release #43

shixued opened this issue Jun 20, 2024 · 1 comment

Comments

@shixued
Copy link

shixued commented Jun 20, 2024

PromiseWorker.prototype.postMessage = function (userMessage) {
  var self = this
  var messageId = messageIds++

  var messageToSend = [messageId, userMessage]

  return new Promise(function (resolve, reject) {
    self._callbacks[messageId] = function (error, result) {
      if (error) {
        return reject(new Error(error.message))
      }
      resolve(result)
    }

    /* istanbul ignore if */
    if (typeof self._worker.controller !== 'undefined') {
      // service worker, use MessageChannels because e.source is broken in Chrome < 51:
      // https://bugs.chromium.org/p/chromium/issues/detail?id=543198
      var channel = new MessageChannel()
      channel.port1.onmessage = function (e) {
        onMessage(self, e)
      }
      self._worker.controller.postMessage(messageToSend, [channel.port2])
    } else {
      // web worker
      self._worker.postMessage(messageToSend)
    }
  })
}

when userMessage is Object,the var messageToSend = [messageId, userMessage] Causing object references not to be released.

image

@nolanlawson
Copy link
Owner

Thanks for reporting! The object should be freed when the message is sent back – you can see here that the callback is cleared:

delete self._callbacks[messageId]

Do you have a reproducible test showing that memory is not freed when it should be freed?

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

2 participants