1

So, I am passing video buffer(Float32Array buffer) to worker thread as a transferable object, it happens for each frame of the video(meaning, continuously video frames are being passed to worker). I did memory profiling, and worker thread is retaining the object, it seems garbage collector doesn't kick in. How to handle this case? I don't think one can invoke GC explicitly in JavaScript.

Here is the code snippet how I am passing video buffer to worker thread:

this.worker.postMessage({
          command: 'SetVideoBuffer',
          data: {
            videoFrame: videoFrame
          }
        },
          [videoFrame.buffer]);

Also, I tried setting the buffer at worker side to 'null', it didn't help.

Any idea how to resolve this, is this chrome thing? Please help.

Thank you!

3
  • So, I did one more thing, and seems like it is working, not a conventional way though, I would really this to be handle by chrome's garbage collector(GC) but here it is what I did - I passed the buffer back to main thread as a transferrable object and explicitly set it to null. It worked for now, not shooting up memory as well. But I would really appreciate if someone can shed more light on this, about this memory handling concept of the browser, what am I missing here, that would be great. And, any other possible solution for this. Commented Jun 3, 2022 at 6:11
  • Does your tab crash eventually? If so, open a bug report. Commented Jun 5, 2022 at 22:59
  • @Kaiido yeah it does sometimes on lower end phones on chrome('Aw, snap!'), but safari on iPhone is giving memory exceeded error, looks like GC is not kicking or there is a memory leak Commented Jun 7, 2022 at 7:26

1 Answer 1

2

So, I got the workaround of this problem, looks like if one sends back the video buffer back to main thread where it was created, GC does kick in and clear the heap.

By using the same, zero-copy(transferable objects) way, I transferred the buffer back to the main thread, memory leak issue got resolved.

Sign up to request clarification or add additional context in comments.

1 Comment

I have found their garbage collector to also do this with transferable objects. My scenario had high cpu load, so I assume that maybe the GC wasn't being allowed to start, to conserve cpu, but I do not know the heuristics of its algorithm. bugzilla.mozilla.org/show_bug.cgi?id=1407691#c25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.