<?xml version="1.0" encoding="iso-8859-1" ?>
<rss version="2.0">
  <channel>
    <title>HtmlEditor</title>
    <link>http://www.itwriting.com/phorum/list.php?3</link>
    <description><![CDATA[For discussion of the .Net HTMLEditor control]]></description>
    <language>EN</language>
    <pubDate>Tue, 22 Apr 2003 01:50:52 +0100</pubDate>
    <lastBuildDate>Tue, 22 Apr 2003 01:50:52 +0100</lastBuildDate>
    <category>HtmlEditor</category>
    <generator>Phorum 5.1.25</generator>
    <ttl>60</ttl>
    <item>
      <title>Re: HtmlEvent Memory leak and a fix</title>
      <link>http://www.itwriting.com/phorum/read.php?3,544,551#msg-551</link>
      <author>James Hancock</author>
      <description><![CDATA[Definately on the right track!<br />
<br />
Yes, it throws the error on the marshal.getdispatch... line.<br />
<br />
Yes, I copied it in and overwrote the CleanupControl function in the htmleditor.cs file.<br />
<br />
Keep up the good work!]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,544,551#msg-551</guid>
      <pubDate>Tue, 22 Apr 2003 01:50:52 +0100</pubDate>
    </item>
    <item>
      <title>Re: HtmlEvent Memory leak and a fix</title>
      <link>http://www.itwriting.com/phorum/read.php?3,544,550#msg-550</link>
      <author>Tim Anderson</author>
      <description><![CDATA[I'm surprised because it runs fine here, even in Win 98. Did you definitely put this in HtmlEditor.cs? Is it the call to Marshal.GetIDispatchForObject that raises the error? <br />
<br />
Having said that, I've changed the code a bit because there are circumstances when CleanupControl doesn't get called. I am on the right lines I think. To demo the issue, I've appended the results from the sample app I did to test grin's memory issue. The app calls showdialog in a loop, using a form on which there is an htmlEditor. The form loads a document and then closes. The loop runs up to 1000.<br />
<br />
Note that if there is no event handler for HtmlEvent, the results are like the 2nd table, even with the &quot;old&quot; htmlEditor:<br />
<br />
Before change<br />
Left column - number of iterations<br />
Right column - memory in bytes reported by GC.GetTotalMemory<br />
<br />
0 	66112 (before showing htmlEditor at all)<br />
100 	265672<br />
200  	410292<br />
300 	563096<br />
400 	715632<br />
500 	868208<br />
600 	1020720<br />
700 	1173184<br />
800 	1325648<br />
900 	1478308<br />
1000 	1632392<br />
<br />
<br />
After change<br />
0 	66112 (before showing htmlEditor at all)<br />
100 	214668<br />
200  	206488<br />
300 	206536<br />
400 	206568<br />
500 	206648<br />
600 	206728<br />
700 	206808<br />
800 	206888<br />
900 	206968<br />
1000 	207048]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,544,550#msg-550</guid>
      <pubDate>Mon, 21 Apr 2003 23:22:37 +0100</pubDate>
    </item>
    <item>
      <title>Re: HtmlEvent Memory leak and a fix</title>
      <link>http://www.itwriting.com/phorum/read.php?3,544,548#msg-548</link>
      <author>James Hancock</author>
      <description><![CDATA[Sorry Tim, this seems to cause a runtime &quot;no such interface supported&quot;<br />
<br />
Commenting it out fixes it again.]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,544,548#msg-548</guid>
      <pubDate>Mon, 21 Apr 2003 20:16:06 +0100</pubDate>
    </item>
    <item>
      <title>HtmlEvent Memory leak and a fix</title>
      <link>http://www.itwriting.com/phorum/read.php?3,544,544#msg-544</link>
      <author>Tim Anderson</author>
      <description><![CDATA[In testing our app for memory leaks I found a significant issue with the htmlEditor. If you have an htmlEditor on a form it never gets disposed (in Net FX 1.1 - not tested 1.0). <br />
<br />
The reason is that setting the control as the event handler for COM events (in SetHTMLEvents method, HtmlEditor.cs) creates a COM reference that never gets released.<br />
<br />
The following amended CleanupControl method seems to fix the problem, let me know of any problems.<br />
<br />
public void CleanupControl()<br />
{<br />
 if (IsCreated)<br />
 {<br />
 if (cookie != -1)<br />
 {<br />
 icp.Unadvise(cookie);<br />
 cookie = -1;<br />
 }<br />
<br />
//new code here to release COM reference to control<br />
if (m_htmldoc != null) <br />
 {<br />
 IntPtr ptr = Marshal.GetIDispatchForObject(this);<br />
 int i = Marshal.Release(ptr);<br />
 while (i &gt; 0)<br />
 {<br />
 i = Marshal.Release(ptr);<br />
 }<br />
}<br />
<br />
site.CloseDocument();<br />
site.Dispose();<br />
site = null;<br />
this.m_htmldoc = null;<br />
}<br />
}]]></description>
      <category>HtmlEditor</category>
      <guid isPermaLink="true">http://www.itwriting.com/phorum/read.php?3,544,544#msg-544</guid>
      <pubDate>Mon, 21 Apr 2003 18:10:16 +0100</pubDate>
    </item>
  </channel>
</rss>
