V8 garbage collector doesnt collect deleted Mat instances using OpenCV.js

33 views
Skip to first unread message

Zigmas Slušnys

unread,
Jul 9, 2019, 11:52:37 AM7/9/19
to v8-users

I am reading a video and storing the Mat instance clones of each frame to an array so I could play it back on demand and also analyze the frames. Once i process the video and store the frames in the array - the memory snapshot increases from 150Mb to 1000Mb within the JSArrayBufferData.

I have to mention that i'm using Vue.js frontend framework to store the array within vue's data observable that's an array.

Same thing happens also if I'm just creating a regular type of class object having an array in.

I've tried deleting and setting each frame to zero just to see if that would release the memory, but nothing seems to work.

I've got a simple example of this here: https://jsfiddle.net/9s51poyd/


I would like to release the memory from chrome, because every time I analize video now or just copy these Mat instances into an array, memory footprint could go up to 9GB. As you can imagine that's not the desired outcome.


Is there a way to release the memory, because garbage collection currently does not work in this case example.

Screenshot 2019-07-09 at 18.25.22.png

Jakob Kummerow

unread,
Jul 9, 2019, 12:04:23 PM7/9/19
to v8-users
The fiddle is broken ("createFrames" is not defined, "frames.push" is not a function, "deleteFrames" is never called; that's when I gave up); please fix it such that it actually reproduces the issue.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/e8ee6213-7ba5-48de-ad27-c80752b4a368%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zigmas Slušnys

unread,
Jul 9, 2019, 1:32:12 PM7/9/19
to v8-users
Hi Jakob, thanks for looking at this. I'm sorry about the faulty example. I fixed most of these smaller issues with naming, however jsfiddle doesn't load the opencv.js file from the source as a resource. I think the only way to try this would be to do it locally.


On Tuesday, July 9, 2019 at 7:04:23 PM UTC+3, Jakob Kummerow wrote:
The fiddle is broken ("createFrames" is not defined, "frames.push" is not a function, "deleteFrames" is never called; that's when I gave up); please fix it such that it actually reproduces the issue.

On Tue, Jul 9, 2019 at 5:52 PM Zigmas Slušnys <zigmas...@gmail.com> wrote:

I am reading a video and storing the Mat instance clones of each frame to an array so I could play it back on demand and also analyze the frames. Once i process the video and store the frames in the array - the memory snapshot increases from 150Mb to 1000Mb within the JSArrayBufferData.

I have to mention that i'm using Vue.js frontend framework to store the array within vue's data observable that's an array.

Same thing happens also if I'm just creating a regular type of class object having an array in.

I've tried deleting and setting each frame to zero just to see if that would release the memory, but nothing seems to work.

I've got a simple example of this here: https://jsfiddle.net/9s51poyd/


I would like to release the memory from chrome, because every time I analize video now or just copy these Mat instances into an array, memory footprint could go up to 9GB. As you can imagine that's not the desired outcome.


Is there a way to release the memory, because garbage collection currently does not work in this case example.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-u...@googlegroups.com.

Zigmas Slušnys

unread,
Jul 9, 2019, 1:34:59 PM7/9/19
to v8-users


On Tuesday, July 9, 2019 at 7:04:23 PM UTC+3, Jakob Kummerow wrote:
The fiddle is broken ("createFrames" is not defined, "frames.push" is not a function, "deleteFrames" is never called; that's when I gave up); please fix it such that it actually reproduces the issue.

On Tue, Jul 9, 2019 at 5:52 PM Zigmas Slušnys <zigmas...@gmail.com> wrote:

I am reading a video and storing the Mat instance clones of each frame to an array so I could play it back on demand and also analyze the frames. Once i process the video and store the frames in the array - the memory snapshot increases from 150Mb to 1000Mb within the JSArrayBufferData.

I have to mention that i'm using Vue.js frontend framework to store the array within vue's data observable that's an array.

Same thing happens also if I'm just creating a regular type of class object having an array in.

I've tried deleting and setting each frame to zero just to see if that would release the memory, but nothing seems to work.

I've got a simple example of this here: https://jsfiddle.net/9s51poyd/


I would like to release the memory from chrome, because every time I analize video now or just copy these Mat instances into an array, memory footprint could go up to 9GB. As you can imagine that's not the desired outcome.


Is there a way to release the memory, because garbage collection currently does not work in this case example.

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups "v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-u...@googlegroups.com.

Ulan Degenbaev

unread,
Jul 9, 2019, 1:45:57 PM7/9/19
to v8-users
Hi Zigmas,

Does the leak also reproduce in other browsers? If so, it might be a leak in the application.

If the leak happens only in Chrome, would you mind filing a bug https://bugs.chromium.org/p/chromium/issues/entry and providing steps to reproduce the leak (e.g. all necessary js files that use Vue and include opencv.js).

Thanks!
Ulan.

To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/21b4e5d0-b150-4c18-9018-a5c783c92b17%40googlegroups.com.

Zigmas Slušnys

unread,
Jul 9, 2019, 1:56:09 PM7/9/19
to v8-users
Thank you for the message. I'll be sure to file a bug then. This happens in firefox as well. The OpenCV.js library is compiled from C++. When i create a `new cv.Mat()` and add it to the array and delete it afterwards it does not garbage collect it even tho its not used anymore in the application with no reference to it. I don't know a way to manually call the garbage collection which I dont think is possible in V8, is it?
Reply all
Reply to author
Forward
0 new messages