# Possible memory leak with video texture in WebGL renderer

**URL:** <https://discourse.processing.org/t/possible-memory-leak-with-video-texture-in-webgl-renderer/16088>\
**Category:** p5.js\
**Created:** [December 3, 2019, 7:16pm UTC](https://discourse.processing.org/t/possible-memory-leak-with-video-texture-in-webgl-renderer/16088 "2019-12-03T19:16:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bzSteve](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bzsteve/32/7358_2.png) [@bzSteve](https://discourse.processing.org/u/bzSteve)\
**Post date:** [December 3, 2019, 7:16pm UTC](https://discourse.processing.org/t/possible-memory-leak-with-video-texture-in-webgl-renderer/16088/1 "2019-12-03T19:16:19Z")

</div>

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](http://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?

```auto
<!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>

```

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [December 7, 2019, 5:36am UTC](https://discourse.processing.org/t/possible-memory-leak-with-video-texture-in-webgl-renderer/16088/2 "2019-12-07T05:36:04Z")

</div>

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

> **[processing/p5.js](https://github.com/processing/p5.js/issues)**
>
> p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Proces...

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 7, 2019, 7:42am UTC](https://discourse.processing.org/t/possible-memory-leak-with-video-texture-in-webgl-renderer/16088/3 "2019-12-07T07:42:54Z")

</div>

when i run it by the online editor  
[https://editor.p5js.org/kll/sketches/rRjOfo2nI](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.

---

<div class="post-metadata">

**Author:** ![bzSteve](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bzsteve/32/7358_2.png) [@bzSteve](https://discourse.processing.org/u/bzSteve)\
**Post date:** [December 7, 2019, 8:18pm UTC](https://discourse.processing.org/t/possible-memory-leak-with-video-texture-in-webgl-renderer/16088/4 "2019-12-07T20:18:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 7, 2019, 9:24pm UTC](https://discourse.processing.org/t/possible-memory-leak-with-video-texture-in-webgl-renderer/16088/5 "2019-12-07T21:24:52Z")

</div>

> <https://github.com/processing/p5.js/issues/4185>
>
> This is a duplicate of an issue I posted to discourse.processing.org a few days ago. I'm new to p5.js, so I...
