Possible memory leak with video texture in WebGL renderer

Hi, I’m brand new to p5.js and I’m enjoying it quite a bit but now I’m experiencing a memory leak using a video texture with a WebGL renderer. I’m on a Mac running macOS 10.15.1 and I’ve tried Safari 13.0.3 and Chrome 78.0.3904.108 with p5.js 0.10.2 from the jsdelivr.net cdn. I am using Activity Monitor to watch memory usage. In each browser, memory usage seems to increase for as long as the sketch runs. If I use a P2D renderer and display the video with the image function, memory is stable. I experience the same problem with any mp4 video that I try. I have not tried other video formats yet.

My use case requires WebGL, so P2D is not a solution for me.

What is the correct way to display a video texture while keeping memory stable?

<!DOCTYPE html>
<html>
    <head>
        <script src="https://cdn.jsdelivr.net/npm/p5@0.10.2/lib/p5.min.js"></script>
    </head>

    <body>
        <script type="text/javascript" charset="utf-8">

let vid

const VIDEO_FILE_NAME = 'https://CommonDataStorage.GoogleApis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4'

function preload( ) {
    vid = createVideo( [ VIDEO_FILE_NAME ], ( ) => {
        vid.size( 480, 360 )
    } )
}

function setup( ) {
    createCanvas( 800, 600, WEBGL )   
}


function draw( ) {
    background( 40, 100, 100 )

//                image( vid, 10, 10 )
    texture( vid )
    box( 480, 360, 20 )
}


function mousePressed( ) {
    vid.loop( )
    vid.hide( )
}

        </script>

    </body>
</html>
1 Like

Questions involving suspected memory leaks might be best to post to the p5.js core developers, here:

when i run it by the online editor
https://editor.p5js.org/kll/sketches/rRjOfo2nI

on a win10 PC / firefox browser / use 3.8GB
open and start sketch
i have a const. memory usage of 3.9GB
no problem here.

1 Like

Thank you for the link, jeremydouglass. Since there’s no obvious problem with my code, I’ll post my issue there as a possible bug.

kil, thank you for trying this. I experience the memory leak with the editor link you provided. I’m wondering if looking at usage expressed in gigabytes is obscuring the slow uptick in memory.

1 Like
1 Like