<?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>31675</bug_id>
          
          <creation_ts>2009-11-19 10:16:22 -0800</creation_ts>
          <short_desc>Memory use grows grows possibly unbounded in this JavaScript Array test case</short_desc>
          <delta_ts>2010-01-15 10:48:47 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Mac (Intel)</rep_platform>
          <op_sys>OS X 10.6</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>HasReduction, InRadar, Regression</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jorge">jorgechamorro</reporter>
          <assigned_to name="Geoffrey Garen">ggaren</assigned_to>
          <cc>ap</cc>
    
    <cc>ggaren</cc>
    
    <cc>jorgechamorro</cc>
    
    <cc>mjs</cc>
    
    <cc>oliver</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>165014</commentid>
    <comment_count>0</comment_count>
    <who name="Jorge">jorgechamorro</who>
    <bug_when>2009-11-19 10:16:22 -0800</bug_when>
    <thetext>Hi,

I&apos;ve run this code in Safari, FF, Opera &amp; Chrome (*). Only Safari fails to GC a&apos;s old content: I&apos;ve been running it in the consoles (just in case it matters).

//Create an array of 8M elements and fill each element with an empty string:

a= new Array(Math.pow(2,23)); n= a.length; while(n--){a[n]=&quot;&quot;;}; n= a.length;

//Repeat again a few times more until it hangs/stops responding (happens both in Safari and in any nightly build):

a= new Array(Math.pow(2,23)); n= a.length; while(n--){a[n]=&quot;&quot;;}; n= a.length;
a= new Array(Math.pow(2,23)); n= a.length; while(n--){a[n]=&quot;&quot;;}; n= a.length;
a= new Array(Math.pow(2,23)); n= a.length; while(n--){a[n]=&quot;&quot;;}; n= a.length;
a= new Array(Math.pow(2,23)); n= a.length; while(n--){a[n]=&quot;&quot;;}; n= a.length;
a= new Array(Math.pow(2,23)); n= a.length; while(n--){a[n]=&quot;&quot;;}; n= a.length;

a&apos;s old content should eventually be GC&apos;ed, but it isn&apos;t and accumulates on each run: it can be seen with a &quot;top&quot; or in the activity monitor. Other browsers do it well.

BTW, why does each array element use so much memory ?
This 8M array filled with &quot;&quot; occupies over 5x more memory in Safari than in Chrome or in Opera. (!)

Cheers,
(*)FF2.0.0.20, FF3.0.13, FF3.5.4, FF3.6b2, Chrome 4.0.249.0, Opera 10.01.
-- 
jorge@jorgechamorro.com</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>165020</commentid>
    <comment_count>1</comment_count>
    <who name="Jorge">jorgechamorro</who>
    <bug_when>2009-11-19 10:44:12 -0800</bug_when>
    <thetext>Added keyword regression: it&apos;s ok in Safari 3.2.3.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>165041</commentid>
    <comment_count>2</comment_count>
    <who name="Jorge">jorgechamorro</who>
    <bug_when>2009-11-19 11:53:08 -0800</bug_when>
    <thetext>Prepare the activity monitor and then surf to:

http://jorgechamorro.com/bug31675.html

RUN and see the memory increasing on each RUN... until it hangs.
-- 
Jorge.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>165064</commentid>
    <comment_count>3</comment_count>
    <who name="Mark Rowe (bdash)">mrowe</who>
    <bug_when>2009-11-19 12:48:44 -0800</bug_when>
    <thetext>&lt;rdar://problem/7409500&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>165075</commentid>
    <comment_count>4</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2009-11-19 13:41:42 -0800</bug_when>
    <thetext>The obvious reason for the large memory usage relative to other engines is that we don&apos;t coalesce array storage when an array is built from top to bottom :-/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178791</commentid>
    <comment_count>5</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2010-01-08 14:03:10 -0800</bug_when>
    <thetext>What I see in one iteration of this test:

- Firefox uses about 350MB but promptly returns to 0. So, it seems to use a sparse array that is promptly GC&apos;d.

- Chrome uses about 25MB but crashes with larger arrays. So, it seems to use a dense array.

- Safari uses about 600MB and does not promptly return to 0.

I&apos;m going to investigate why Safari&apos;s sparse array is so space-hungry, and why it doesn&apos;t return to 0.

Making the array dense once it&apos;s filled might help a bit, but it won&apos;t help with the initial 600MB.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178816</commentid>
    <comment_count>6</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2010-01-08 14:42:45 -0800</bug_when>
    <thetext>malloc-history confirms that, for a single run, 268MB is allocated by the sparse map. That&apos;s enough space for about 2 * 2^23 entries. (There are 2^23 entries, and the map doesn&apos;t want to be more than half full.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178860</commentid>
    <comment_count>7</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2010-01-08 16:06:34 -0800</bug_when>
    <thetext>Also, it looks like arrays don&apos;t report extra cost for their sparse storage, which would explain, on multiple runs, why no arrays are ever GC&apos;d, and memory keeps growing.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178879</commentid>
    <comment_count>8</comment_count>
      <attachid>46178</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2010-01-08 16:50:32 -0800</bug_when>
    <thetext>Created attachment 46178
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178880</commentid>
    <comment_count>9</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2010-01-08 16:54:21 -0800</bug_when>
    <thetext>(ChangeLog tabs fixed in local copy.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178881</commentid>
    <comment_count>10</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2010-01-08 16:55:18 -0800</bug_when>
    <thetext>Attachment 46178 did not pass style-queue:

Failed to run &quot;WebKitTools/Scripts/check-webkit-style&quot; exit_code: 1
JavaScriptCore/ChangeLog:8:  Line contains tab character.  [whitespace/tab] [5]
JavaScriptCore/ChangeLog:9:  Line contains tab character.  [whitespace/tab] [5]
JavaScriptCore/ChangeLog:11:  Line contains tab character.  [whitespace/tab] [5]
JavaScriptCore/ChangeLog:15:  Line contains tab character.  [whitespace/tab] [5]
Total errors found: 4</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178883</commentid>
    <comment_count>11</comment_count>
      <attachid>46178</attachid>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2010-01-08 16:59:43 -0800</bug_when>
    <thetext>Comment on attachment 46178
Patch

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>178884</commentid>
    <comment_count>12</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2010-01-08 17:02:54 -0800</bug_when>
    <thetext>Committed r53025: &lt;http://trac.webkit.org/changeset/53025&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>179136</commentid>
    <comment_count>13</comment_count>
    <who name="Jorge">jorgechamorro</who>
    <bug_when>2010-01-10 07:37:36 -0800</bug_when>
    <thetext>(In reply to comment #12)
&gt; Committed r53025: &lt;http://trac.webkit.org/changeset/53025&gt;

Hi Geoffrey,

Sorry for spoiling the fun :-) but there must be -I believe- something else...

I&apos;ve put two buttons more in the test page, one to null &quot;a&quot;, and one to reload the page:

ISTM that a&apos;s (old contents) memory is never freed/gc&apos;ed/released, not even after nulling a nor after nulling a and reloading, nor after nulling a and closing the window/tab, even when/if other tabs/windows would need it. Chrome, Opera and FF eventually release it, but our much beloved Safari still doesn&apos;t.

Oh, and btw, memory use still grows up to 2GB (!) in a MBP in 64 bits mode (~1GB in 32bits mode), but in Chrome in takes less than 100MB, in Opera less than 300Mb, and in FF less that 500MB ! 

May it have to do with the page cache ?

Cheers,
-- 
Jorge.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>179530</commentid>
    <comment_count>14</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2010-01-11 13:58:53 -0800</bug_when>
    <thetext>(In reply to comment #13)
Your new test uses more memory than your old test because your new test allocates a larger array.

I don&apos;t know what combination of &quot;f()&quot; and/or &quot;null&quot; and/or &quot;reload&quot; you&apos;re using, so I&apos;m not sure if I tested the way you did.

I don&apos;t know how you measured whether memory was freed, but I found that reloading and closing the window did free memory. I suspect you may be re-reporting bug 28676.

&gt; Oh, and btw, memory use still grows up to 2GB (!) in a MBP in 64 bits mode
&gt; (~1GB in 32bits mode), but in Chrome in takes less than 100MB, in Opera less
&gt; than 300Mb, and in FF less that 500MB ! 

I don&apos;t think the Chrome numbers are relevant, since they represent the prima facia unacceptable policy of blindly allocating buffers to user requested sizes, even if doing so means crashing.

But it would be nice to do something a bit smarter in the case of large arrays that start out sparse and become non-sparse.

&gt; May it have to do with the page cache ?

No.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>181275</commentid>
    <comment_count>15</comment_count>
    <who name="Jorge">jorgechamorro</who>
    <bug_when>2010-01-15 10:48:47 -0800</bug_when>
    <thetext>(In reply to comment #14)
&gt; 
&gt; I don&apos;t know how you measured whether memory was freed, but I found that
&gt; reloading and closing the window did free memory.

I click on run() then on a=null the on run() then on a=null etc many times, and the memory use (as seen in the activity monitor system memory pie chart (in yellow)) keeps ever increasing. A reload() does not release it either. Nor closing the tab/window. But a cmd-Q does.

&gt; I suspect you may be re-reporting bug 28676.

Maybe. If the memory is ever deallocated it is not being returned to the system. But ISTM that it&apos;s not being reused internally either: if it were, why would memory use keep ever increasing (?).</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>46178</attachid>
            <date>2010-01-08 16:50:32 -0800</date>
            <delta_ts>2010-01-08 16:59:43 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-31675-20100108165030.patch</filename>
            <type>text/plain</type>
            <size>2911</size>
            <attacher name="Geoffrey Garen">ggaren</attacher>
            
              <data encoding="base64">SW5kZXg6IEphdmFTY3JpcHRDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBKYXZhU2NyaXB0
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDUzMDI0KQorKysgSmF2YVNjcmlwdENvcmUvQ2hhbmdl
TG9nCSh3b3JraW5nIGNvcHkpCkBAIC0xLDMgKzEsMjAgQEAKKzIwMTAtMDEtMDggIEdlb2ZmcmV5
IEdhcmVuICA8Z2dhcmVuQGFwcGxlLmNvbT4KKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkg
KE9PUFMhKS4KKworICAgICAgICBNZW1vcnkgdXNlIGdyb3dzIGdyb3dzIHBvc3NpYmx5IHVuYm91
bmRlZCBpbiB0aGlzIEphdmFTY3JpcHQgQXJyYXkgdGVzdCBjYXNlCisgICAgICAgIGh0dHBzOi8v
YnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0zMTY3NQorCisJVGhpcyBmaXhlcyBvbmUg
b2JzZXJ2ZWQgYnVnIGluIHRoaXMgdGVzdCBjYXNlLCB3aGljaCBpcyB0aGF0CisJYXJyYXlzIGRv
bid0IHJlcG9ydCBleHRyYSBjb3N0IGZvciB0aGUgc3BhcnNlIHZhbHVlIG1hcHMuCisKKwlTdW5T
cGlkZXIgcmVwb3J0cyBhIHNtYWxsIHNwZWVkdXAuCisKKyAgICAgICAgKiBydW50aW1lL0p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FwYWNpdHkpICogKHNpemVvZih1bnNpZ25lZCkgKyBzaXplb2Yo
SlNWYWx1ZSkpKTsKKyAgICAgICAgICAgICAgICBzdG9yYWdlLT5yZXBvcnRlZE1hcENhcGFjaXR5
ID0gY2FwYWNpdHk7CisgICAgICAgICAgICB9CiAgICAgICAgICAgICByZXR1cm47CiAgICAgICAg
IH0KICAgICB9CkluZGV4OiBKYXZhU2NyaXB0Q29yZS9ydW50aW1lL0pTQXJyYXkuaAo9PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09Ci0tLSBKYXZhU2NyaXB0Q29yZS9ydW50aW1lL0pTQXJyYXkuaAkocmV2aXNpb24gNTI5OTMp
CisrKyBKYXZhU2NyaXB0Q29yZS9ydW50aW1lL0pTQXJyYXkuaAkod29ya2luZyBjb3B5KQpAQCAt
MzIsNiArMzIsNyBAQCBuYW1lc3BhY2UgSlNDIHsKICAgICAgICAgdW5zaWduZWQgbV9udW1WYWx1
ZXNJblZlY3RvcjsKICAgICAgICAgU3BhcnNlQXJyYXlWYWx1ZU1hcCogbV9zcGFyc2VWYWx1ZU1h
cDsKICAgICAgICAgdm9pZCogbGF6eUNyZWF0aW9uRGF0YTsgLy8gQSBKU0FycmF5IHN1YmNsYXNz
IGNhbiB1c2UgdGhpcyB0byBmaWxsIHRoZSB2ZWN0b3IgbGF6aWx5LgorICAgICAgICBzaXplX3Qg
cmVwb3J0ZWRNYXBDYXBhY2l0eTsKICAgICAgICAgSlNWYWx1ZSBtX3ZlY3RvclsxXTsKICAgICB9
OwogCg==
</data>
<flag name="review"
          id="28401"
          type_id="1"
          status="+"
          setter="oliver"
    />
          </attachment>
      

    </bug>

</bugzilla>