<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>218100</bug_id>
          
          <creation_ts>2020-10-22 14:47:34 -0700</creation_ts>
          <short_desc>Rapidly resizing a WebGL-rendered canvas leaks memory</short_desc>
          <delta_ts>2021-08-30 06:32:52 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebGL</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>217212</dup_id>
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=219780</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=229606</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>217212</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Kenneth Russell">kbr</reporter>
          <assigned_to name="Kenneth Russell">kbr</assigned_to>
          <cc>dino</cc>
    
    <cc>jdarpinian</cc>
    
    <cc>kkinnunen</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1700847</commentid>
    <comment_count>0</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-22 14:47:34 -0700</bug_when>
    <thetext>Sebastien Vandenberghe from Microsoft&apos;s Babylon.js team reports that rapidly resizing a WebGL-rendered canvas leaks significant amounts of memory:
https://jsfiddle.net/kr0atxuf/2/

Safari reloads the tab after about 30 seconds because it&apos;s consuming too much memory. This happens repeatedly until the browser says it failed too many times.

This is reproducible in Safari Technology Preview 114 on macOS 10.15.7, so isn&apos;t fixed by the ANGLE backend.

Looking into Source/WebCore/platform/graphics/cocoa/WebGLLayer.mm, while the old IOSurfaces should be being cleaned up because they&apos;re held onto via std::unique_ptr, it looks like perhaps other associated graphics resources aren&apos;t being cleaned up properly.

Filing as Major severity because this will significantly impact WebGL applications&apos; reliability.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1700879</commentid>
    <comment_count>1</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-22 16:28:35 -0700</bug_when>
    <thetext>After preparing a patch fixing this against somewhat old WebKit sources and rebasing to top-of-tree, I found Kimmo&apos;s fix for Bug 209139 might have already fixed this. Rebuilding to see.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1700880</commentid>
    <comment_count>2</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-22 16:29:02 -0700</bug_when>
    <thetext>Sorry, that should have been Bug 217212.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1700895</commentid>
    <comment_count>3</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-22 17:15:16 -0700</bug_when>
    <thetext>Yes, Kimmo&apos;s fix for Bug 217212 fixed this memory leak.

I&apos;ll ask about getting that merged into the Safari 14 release branch.

*** This bug has been marked as a duplicate of bug 217212 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1700929</commentid>
    <comment_count>4</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2020-10-22 23:13:01 -0700</bug_when>
    <thetext>I&apos;ll dupe it to bug 217581 which is open.

Although I tried to be a bit more meticulous with the underlying gpu object references when refactoring, I don&apos;t think the original code had that significant leaks (that the new code does not, at least).

*** This bug has been marked as a duplicate of bug 217581 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1701183</commentid>
    <comment_count>5</comment_count>
    <who name="Kenneth Russell">kbr</who>
    <bug_when>2020-10-23 18:30:02 -0700</bug_when>
    <thetext>The original code leaked EGL pbuffers that were associated with the IOSurfaces, and it looked to me like those were somehow retaining the IOSurfaces. Fixing the leak in the old [WebGLLayer allocateIOSurfaceBackingStoreWithSize:usingAlpha:] method definitely addressed the previous leak, which also doesn&apos;t exist after the fix for Bug 217212.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1701202</commentid>
    <comment_count>6</comment_count>
    <who name="Kimmo Kinnunen">kkinnunen</who>
    <bug_when>2020-10-23 21:04:05 -0700</bug_when>
    <thetext>&gt; The original code leaked EGL pbuffers that were associated with the IOSurfaces, and it looked to me like those were somehow retaining the IOSurfaces

EGL pbuffers do retain the iosurfaces and unretain only in destructors. 
I&apos;ll take your word on the original code leaking pbuffers and dupe this back.

*** This bug has been marked as a duplicate of bug 217212 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>