OK, here is a small example that shows the problem.  I&#39;m monitoring the memory using task manager.  When the render line is commented out the memory stays constant as you mouse over the image.  However, if that line is uncommented then then memory climbs rapidly.  The program crashes when you exit, but that doesn&#39;t concern me right now, I&#39;m focused on the memory leak.<div>
<br></div><div>Thanks<br><div><br></div><div><pre style="margin-top:0px;margin-bottom:0px"><span style="color:#000080">#include</span><span style="color:#c0c0c0"> </span><span style="color:#008000">&lt;QtGui/QApplication&gt;</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#000080">#include</span><span style="color:#c0c0c0"> </span><span style="color:#008000">&lt;QMainWindow&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#000080">#include</span><span style="color:#c0c0c0"> </span><span style="color:#008000">&lt;QVTKWidget2.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#000080">#include</span><span style="color:#c0c0c0"> </span><span style="color:#008000">&lt;vtkImageViewer2.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#000080">#include</span><span style="color:#c0c0c0"> </span><span style="color:#008000">&lt;vtkImageData.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#000080">#include</span><span style="color:#c0c0c0"> </span><span style="color:#008000">&lt;vtkPointData.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#000080">#include</span><span style="color:#c0c0c0"> </span><span style="color:#008000">&lt;vtkGenericOpenGLRenderWindow.h&gt;</span></pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#808000">class</span><span style="color:#c0c0c0"> </span><span style="color:#800080">MyQVTKWidget2</span><span style="color:#c0c0c0"> </span>:<span style="color:#c0c0c0"> </span><span style="color:#808000">public</span><span style="color:#c0c0c0"> </span><span style="color:#800080">QVTKWidget2</span><span style="color:#c0c0c0"> </span>{</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#808000">public</span>:</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">MyQVTKWidget2</span><span style="color:#c0c0c0"> </span>(<span style="color:#800080">vtkImageViewer2</span><span style="color:#c0c0c0"> </span>*imageViewer,<span style="color:#c0c0c0"> </span><span style="color:#800080">QWidget</span><span style="color:#c0c0c0"> </span>*parent<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>)<span style="color:#c0c0c0"> </span>:<span style="color:#c0c0c0"> </span><span style="color:#800080">QVTKWidget2</span>(parent)<span style="color:#c0c0c0"> </span>{</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">        </span><span style="color:#808000">this</span>-&gt;<span style="color:#800000">imageViewer</span><span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span>imageViewer;</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>}</pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#808000">virtual</span><span style="color:#c0c0c0"> </span>~<span style="font-style:italic">MyQVTKWidget2</span>()<span style="color:#c0c0c0"> </span>{</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">        </span><span style="color:#800000">imageViewer</span>-&gt;<span style="font-style:italic">Delete</span>();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>}</pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#808000">void</span><span style="color:#c0c0c0"> </span><span style="font-style:italic">mouseMoveEvent</span>(<span style="color:#800080">QMouseEvent</span><span style="color:#c0c0c0"> </span>*)<span style="color:#c0c0c0"> </span>{</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">        </span><span style="color:#008000">//</span><span style="color:#c0c0c0"> </span><span style="color:#008000">Comment</span><span style="color:#c0c0c0"> </span><span style="color:#008000">out</span><span style="color:#c0c0c0"> </span><span style="color:#008000">this</span><span style="color:#c0c0c0"> </span><span style="color:#008000">line</span><span style="color:#c0c0c0"> </span><span style="color:#008000">to</span><span style="color:#c0c0c0"> </span><span style="color:#008000">see</span><span style="color:#c0c0c0"> </span><span style="color:#008000">the</span><span style="color:#c0c0c0"> </span><span style="color:#008000">memory</span><span style="color:#c0c0c0"> </span><span style="color:#008000">stay</span><span style="color:#c0c0c0"> </span><span style="color:#008000">constant</span></pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">        </span><span style="color:#800000">imageViewer</span>-&gt;<span style="font-style:italic">Render</span>();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>}</pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#808000">private</span>:</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">vtkImageViewer2</span><span style="color:#c0c0c0"> </span>*<span style="color:#800000">imageViewer</span>;</pre>

<pre style="margin-top:0px;margin-bottom:0px">};</pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#808000">int</span><span style="color:#c0c0c0"> </span>main(<span style="color:#808000">int</span><span style="color:#c0c0c0"> </span>argc,<span style="color:#c0c0c0"> </span><span style="color:#808000">char</span><span style="color:#c0c0c0"> </span>*argv[])<span style="color:#c0c0c0"> </span>{</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">QApplication</span><span style="color:#c0c0c0"> </span>a(argc,<span style="color:#c0c0c0"> </span>argv);</pre>

<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">vtkImageData</span><span style="color:#c0c0c0"> </span>*imageData<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span><span style="color:#800080">vtkImageData</span>::New();</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageData-&gt;<span style="font-style:italic">SetExtent</span>(<span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">100</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">100</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">100</span>);</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageData-&gt;<span style="font-style:italic">SetOrigin</span>(<span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>);</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageData-&gt;<span style="font-style:italic">SetSpacing</span>(<span style="color:#000080">1</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">1</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">1</span>);</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageData-&gt;<span style="font-style:italic">AllocateScalars</span>();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageData-&gt;GetPointData()-&gt;GetScalars()-&gt;<span style="font-style:italic">FillComponent</span>(<span style="color:#000080">0</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">0</span>);</pre>

<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">vtkImageViewer2</span><span style="color:#c0c0c0"> </span>*imageViewer<span style="color:#c0c0c0"> </span>=<span style="color:#c0c0c0"> </span><span style="color:#800080">vtkImageViewer2</span>::New();</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageViewer-&gt;<span style="font-style:italic">SetInput</span>(imageData);</pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">MyQVTKWidget2</span><span style="color:#c0c0c0"> </span>widget(imageViewer);</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageViewer-&gt;<span style="font-style:italic">SetRenderWindow</span>(widget.<span style="font-style:italic">GetRenderWindow</span>());</pre>

<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#800080">QMainWindow</span><span style="color:#c0c0c0"> </span>mainWindow;</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>mainWindow.setGeometry(<span style="color:#000080">200</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">200</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">300</span>,<span style="color:#c0c0c0"> </span><span style="color:#000080">300</span>);</pre>

<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>mainWindow.setCentralWidget(&amp;widget);</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>mainWindow.show();</pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span>imageData-&gt;<span style="font-style:italic">Delete</span>();</pre>
<pre style="margin-top:0px;margin-bottom:0px"><span style="color:#c0c0c0">    </span><span style="color:#808000">return</span><span style="color:#c0c0c0"> </span>a.exec();</pre>
<pre style="margin-top:0px;margin-bottom:0px">}</pre>
<pre style="margin-top:0px;margin-bottom:0px"></pre><br><div class="gmail_quote">On Fri, Feb 24, 2012 at 1:36 PM, Jonathan Morra <span dir="ltr">&lt;<a href="mailto:jonmorra@gmail.com">jonmorra@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I will spend some time and try and put together a small self contained test.<div class="HOEnZb"><div class="h5"><br><br>
<div class="gmail_quote">On Fri, Feb 24, 2012 at 1:29 PM, Clinton Stimpson <span dir="ltr">&lt;<a href="mailto:clinton@elemtech.com" target="_blank">clinton@elemtech.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Friday, February 24, 2012 02:19:59 pm Jonathan Morra wrote:<br>
&gt; I have recently converted my app from using QVTKWidget to QVTKWidget2 so<br>
&gt; that I could paint on the QVTKWidget2 (which I was able to successfully<br>
&gt; do).  After this conversion my app started to leak memory terribly.  I<br>
&gt; followed the memory leak around, and found the culprit is the following<br>
&gt; line<br>
&gt;<br>
&gt; glTexImage2D(GL_TEXTURE_2D, 0, internalFormat,<br>
&gt;<br>
&gt;                    xsize, ysize, 0, format,<br>
&gt;<br>
&gt;                    GL_UNSIGNED_BYTE, static_cast&lt;const GLvoid *&gt;(data));<br>
&gt;<br>
&gt;<br>
&gt; Which is in the following function<br>
&gt;<br>
&gt;<br>
&gt; void vtkOpenGLImageSliceMapper::RenderTexturedPolygon(<br>
&gt;<br>
&gt;   vtkRenderer *ren, vtkImageProperty *property,<br>
&gt;<br>
&gt;   vtkImageData *input, int extent[6], bool recursive)<br>
&gt;<br>
&gt;<br>
&gt; I am using a build that I got from git on January 10th.  I have a 64<br>
&gt; bit Windows 7 machine, but have built VTK with Microsoft Visual<br>
&gt; Studios 2008 32 bit.<br>
&gt;<br>
&gt;<br>
&gt; This bug is manifested everytime I call render on a QVTKWidget2 that I<br>
&gt; have placed a vtkImageViewer2 in.  This is a very critical bug for us<br>
&gt; as now our program runs out of memory very quickly because there are<br>
&gt; situations where render is called on every mouse move which means the<br>
&gt; program will die extremely fast.  Any help would be appreciated.<br>
&gt;<br>
<br>
</div></div>Ok, I see the cause of the problem.<br>
<br>
QVTKWidget2::Start() calls OpenGLInit(), which resets the context creation<br>
time and the vtkOpenGLImageSliceMapper reloads them thinking its a new<br>
context.<br>
<br>
It would helpful if you can provide a minimal test case to demonstrate this.<br>
<span><font color="#888888"><br>
--<br>
Clinton Stimpson<br>
Elemental Technologies, Inc<br>
Computational Simulation Software, LLC<br>
<a href="http://www.csimsoft.com" target="_blank">www.csimsoft.com</a><br>
</font></span></blockquote></div><br>
</div></div></blockquote></div><br></div></div>