<?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>275331</bug_id>
          
          <creation_ts>2024-06-10 13:56:10 -0700</creation_ts>
          <short_desc>[CG] An Image with video source may allocate too much memory for caching all the video frames</short_desc>
          <delta_ts>2024-07-08 08:53:31 -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>Images</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>REOPENED</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>276319</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Said Abou-Hallawa">sabouhallawa</reporter>
          <assigned_to name="Said Abou-Hallawa">sabouhallawa</assigned_to>
          <cc>commit-queue</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2040671</commentid>
    <comment_count>0</comment_count>
    <who name="Said Abou-Hallawa">sabouhallawa</who>
    <bug_when>2024-06-10 13:56:10 -0700</bug_when>
    <thetext>If a video has at least hundreds of frames and the size of each frame is large, one image like this &lt;img src=&quot;video.mp4&quot;&gt; may allocate multiple of gigabytes.

ImageDecoderAVFObjC::createFrameImageAtIndex() decodes a frame of the video and returns a CGImage for this frame. But it caches the returned CGImage also to avoid decoding it multiple times. Unfortunately this is not how decoding the animated image works.

BitmapImageSource manages the cache of the decoded frames and under memory pressure BitmapImageSource::destroyDecodedData() releases all frames which it does not need to render the current frame.

BitmapImageSource::destroyDecodedData() calls also ImageDecoderAVFObjC::clearFrameBufferCache() to let it release any cached data. But the caches in BitmapImageSource and ImageDecoderAVFObjC can get of sync because BitmapImageSource does not communicate what frames it actually released. So ImageDecoderAVFObjC may end up holding many CGImages BitmapImageSource does not know anything about.

ImageDecoderAVFObjC should not cache any decoded frame. ImageDecoderAVFObjC::clearFrameBufferCache() should be just an empty function.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2040672</commentid>
    <comment_count>1</comment_count>
    <who name="Said Abou-Hallawa">sabouhallawa</who>
    <bug_when>2024-06-10 13:56:44 -0700</bug_when>
    <thetext>rdar://126993116</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2040674</commentid>
    <comment_count>2</comment_count>
    <who name="Said Abou-Hallawa">sabouhallawa</who>
    <bug_when>2024-06-10 14:11:49 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/29688</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2040872</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-06-11 15:14:38 -0700</bug_when>
    <thetext>Committed 279926@main (22ed0bf86c1f): &lt;https://commits.webkit.org/279926@main&gt;

Reviewed commits have been landed. Closing PR #29688 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2045090</commentid>
    <comment_count>4</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2024-07-08 08:53:31 -0700</bug_when>
    <thetext>Re-opened since this is blocked by bug 276319</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>