<?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>126610</bug_id>
          
          <creation_ts>2014-01-07 17:54:50 -0800</creation_ts>
          <short_desc>Memory leak from windowScriptObjectAvailable</short_desc>
          <delta_ts>2014-01-30 19:58:51 -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>WebKit API</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WORKSFORME</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Alex Christensen">alex.christensen</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>ggaren</cc>
    
    <cc>mhahnenberg</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>965277</commentid>
    <comment_count>0</comment_count>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-07 17:54:50 -0800</bug_when>
    <thetext>I&apos;m working on finding a memory leak in Source/WebKit/win.  We are getting a JSContextRef from the call to windowScriptObjectAvailable in WebFrameLoaderClient::dispatchDidClearWindowObjectInWorld.  The JSContextRef has an extra reference to it that is not being dereferenced when we call WebView::close, and it&apos;s causing our JSObjectFinalizeCallback not to be called.  I&apos;m not sure where exactly to look, but it feels like a release of some sort should be added to WebView::close.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>966094</commentid>
    <comment_count>1</comment_count>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-09 15:20:54 -0800</bug_when>
    <thetext>Inspired by https://bugs.webkit.org/attachment.cgi?id=93818&amp;action=prettypatch I added vm.heap.collectAllGarbage() to JSGlobalContextRelease and it fixed my problem without appearing to break anything.  That&apos;s not optimal performance, and that&apos;s certainly not a good fix, but I think it&apos;s close.  Is there a reason we aren&apos;t garbage collecting at all in JSGlobalContextRelease at all anymore?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>966460</commentid>
    <comment_count>2</comment_count>
      <attachid>220862</attachid>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-10 10:55:54 -0800</bug_when>
    <thetext>Created attachment 220862
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>966464</commentid>
    <comment_count>3</comment_count>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-10 10:58:55 -0800</bug_when>
    <thetext>This patch feels super hacky, and I&apos;m sure there&apos;s a better way, and I&apos;m sure there are reasons to not garbage collect when closing a WebView.  I&apos;m expecting an r-, but hopefully some insight about how to do this better.

It would be really nice if there were a way to initiate garbage collection from a JSContextRef, so an API user can tell JavaScriptCore that now is a good time to garbage collect based on the state of my application that JavaScript doesn&apos;t know about.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>966489</commentid>
    <comment_count>4</comment_count>
      <attachid>220862</attachid>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2014-01-10 11:57:35 -0800</bug_when>
    <thetext>Comment on attachment 220862
Patch

A better way to do this is to call GCController::garbageCollectSoon(). Can you try that?

GCController::garbageCollectSoon() does a better job of batching collection requests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>967931</commentid>
    <comment_count>5</comment_count>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-14 11:06:07 -0800</bug_when>
    <thetext>Adding a call to GCController::garbageCollectNow to WebView::close solves my problem, but GCController::garbageCollectSoon does not.  I&apos;m not sure if every user of WebKit on Windows would want the lag of garbage collecting when closing a WebView.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>967934</commentid>
    <comment_count>6</comment_count>
      <attachid>221181</attachid>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-14 11:15:23 -0800</bug_when>
    <thetext>Created attachment 221181
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>967979</commentid>
    <comment_count>7</comment_count>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-14 12:41:06 -0800</bug_when>
    <thetext>I found a solution using the JavaScript API that works for me and doesn&apos;t force other WebKit users to garbage collect when they don&apos;t want to.  I call JSReportExtraMemoryCost(ctx,1000000000); then JSGarbageCollect(ctx); and it garbage collects when I open the next WebKit widget.  This is also hacky, but I can refine it on my end without changing WebKit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>967982</commentid>
    <comment_count>8</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2014-01-14 12:51:34 -0800</bug_when>
    <thetext>Where is the extra reference to the JSContextRef coming from? Maybe the ref count is zero, but you&apos;re not sweeping anything so finalization never happens? Does the IncrementalSweeper work on Windows?

collectAllGarbage also forces eager sweeping, which is why it would cause finalization to happen.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>968011</commentid>
    <comment_count>9</comment_count>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-14 13:31:42 -0800</bug_when>
    <thetext>(In reply to comment #7)
&gt; I call JSReportExtraMemoryCost(ctx,1000000000); then JSGarbageCollect(ctx);
For the record, this is a terrible solution, and the garbage collector keeps the memory usage to a few megabytes when JSReportExtraMemoryCost is used correctly, which is reasonable.

(In reply to comment #8)
&gt; Where is the extra reference to the JSContextRef coming from? Maybe the ref count is zero, but you&apos;re not sweeping anything so finalization never happens? Does the IncrementalSweeper work on Windows?
I&apos;m not sure, but the ref count of the JSContextRef is always between 2 and 4.  Doing extra releases causes crashes, so there&apos;s probably something global that I wasn&apos;t expecting to be global.  
&gt; 
&gt; collectAllGarbage also forces eager sweeping, which is why it would cause finalization to happen.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>968056</commentid>
    <comment_count>10</comment_count>
    <who name="Mark Hahnenberg">mhahnenberg</who>
    <bug_when>2014-01-14 14:48:29 -0800</bug_when>
    <thetext>I would do some further investigation into whether or not sweeping is being triggered in a timely manner. Try adding a printf or breakpoint inside MarkedBlock::sweep and see if things are being swept after the WebView is closed. Sweeping is when finalizers are run, so if a finalizer isn&apos;t running that should be the first thing to check.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>974188</commentid>
    <comment_count>11</comment_count>
      <attachid>221181</attachid>
    <who name="Alex Christensen">alex.christensen</who>
    <bug_when>2014-01-30 19:58:51 -0800</bug_when>
    <thetext>Comment on attachment 221181
Patch

I&apos;m cleaning up old bugs.  This does not need to go in.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>220862</attachid>
            <date>2014-01-10 10:55:54 -0800</date>
            <delta_ts>2014-01-14 11:15:13 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-126610-20140110115552.patch</filename>
            <type>text/plain</type>
            <size>1164</size>
            <attacher name="Alex Christensen">alex.christensen</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJLaXQvd2luL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2Uv
V2ViS2l0L3dpbi9DaGFuZ2VMb2cJKHJldmlzaW9uIDE2MTY1MikKKysrIFNvdXJjZS9XZWJLaXQv
d2luL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE0IEBACisyMDE0LTAxLTEw
ICBBbGV4IENocmlzdGVuc2VuICA8YWNocm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3RBbGxHYXJiYWdlKCk7CisK
ICNpZiBVU0UoQUNDRUxFUkFURURfQ09NUE9TSVRJTkcpCiAgICAgc2V0QWNjZWxlcmF0ZWRDb21w
b3NpdGluZyhmYWxzZSk7CiAjZW5kaWYK
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>221181</attachid>
            <date>2014-01-14 11:15:23 -0800</date>
            <delta_ts>2014-01-30 19:58:51 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-126610-20140114121726.patch</filename>
            <type>text/plain</type>
            <size>1298</size>
            <attacher name="Alex Christensen">alex.christensen</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJLaXQvd2luL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2Uv
V2ViS2l0L3dpbi9DaGFuZ2VMb2cJKHJldmlzaW9uIDE2MTk4NSkKKysrIFNvdXJjZS9XZWJLaXQv
d2luL0NoYW5nZUxvZwkod29ya2luZyBjb3B5KQpAQCAtMSwzICsxLDE0IEBACisyMDE0LTAxLTE0
ICBBbGV4IENocmlzdGVuc2VuICA8YWxleC5jaHJpc3RlbnNlbkBmbGV4c2ltLmNvbT4KKworICAg
ICAgICBGaXhlZCBtZW1vcnkgbGVhayB3aGlsZSB1c2luZyBKYXZhU2NyaXB0IEFQSSBvbiBXaW5k
b3dzLgorICAgICAgICBodHRwczovL2J1Z3Mud2Via2l0Lm9yZy9zaG93X2J1Zy5jZ2k/aWQ9MTI2
NjEwCisKKyAgICAgICAgUmV2aWV3ZWQgYnkgTk9CT0RZIChPT1BTISkuCisKKyAgICAgICAgKiBX
ZWJWaWV3LmNwcDoKKyAgICAgICAgKFdlYlZpZXc6OmNsb3NlKToKKyAgICAgICAgR2FyYmFnZSBj
b2xsZWN0IHdoZW4gY2xvc2luZyBhIFdlYlZpZXcuCisKIDIwMTQtMDEtMTAgIEFuZGVycyBDYXJs
c3NvbiAgPGFuZGVyc2NhQGFwcGxlLmNvbT4KIAogICAgICAgICBUd2VhayBQcm9ncmVzc1RyYWNr
ZXJDbGllbnQgZnVuY3Rpb25zCkluZGV4OiBTb3VyY2UvV2ViS2l0L3dpbi9XZWJWaWV3LmNwcAo9
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09Ci0tLSBTb3VyY2UvV2ViS2l0L3dpbi9XZWJWaWV3LmNwcAkocmV2aXNpb24gMTYw
Nzk1KQorKysgU291cmNlL1dlYktpdC93aW4vV2ViVmlldy5jcHAJKHdvcmtpbmcgY29weSkKQEAg
LTMxLDYgKzMxLDcgQEAKICNpbmNsdWRlICJDT01WYXJpYW50U2V0dGVyLmgiCiAjaW5jbHVkZSAi
RE9NQ29yZUNsYXNzZXMuaCIKICNpbmNsdWRlICJGdWxsc2NyZWVuVmlkZW9Db250cm9sbGVyLmgi
CisjaW5jbHVkZSAiR0NDb250cm9sbGVyLmgiCiAjaW5jbHVkZSAiTWFyc2hhbGxpbmdIZWxwZXJz
LmgiCiAjaW5jbHVkZSAiU29mdExpbmtpbmcuaCIKICNpbmNsdWRlICJTdWJmcmFtZUxvYWRlci5o
IgpAQCAtNzAxLDYgKzcwMiw4IEBAIEhSRVNVTFQgU1RETUVUSE9EQ0FMTFRZUEUgV2ViVmlldzo6
Y2xvc2UKIAogICAgIG1fZGlkQ2xvc2UgPSB0cnVlOwogCisgICAgZ2NDb250cm9sbGVyKCkuZ2Fy
YmFnZUNvbGxlY3ROb3coKTsKKwogI2lmIFVTRShBQ0NFTEVSQVRFRF9DT01QT1NJVElORykKICAg
ICBzZXRBY2NlbGVyYXRlZENvbXBvc2l0aW5nKGZhbHNlKTsKICNlbmRpZgo=
</data>
<flag name="review"
          id="245047"
          type_id="1"
          status="-"
          setter="alex.christensen"
    />
          </attachment>
      

    </bug>

</bugzilla>