Hi Sebastian,  <br><br>Thanks for giving me a place to start.  I&#39;ll take a look at my various pipelines and see where/if I&#39;m doing things like that.  I probably am, since that kind of line saving is just what I&#39;d do.<br>
<br>I&#39;ll let you and the list know.<br><br>Mark<br><br><div class="gmail_quote">On Wed, Nov 24, 2010 at 9:37 AM, Sebastien Jourdain <span dir="ltr">&lt;<a href="mailto:sebastien.jourdain@kitware.com">sebastien.jourdain@kitware.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi Mark,<br>
<br>
it might be related to the way you bind vtk object together. I mean by<br>
bind something like the following expression.<br>
<br>
actor.SetMapper( object.GetMapper() );<br>
<br>
In fact VTK can have some issue with reference count if you provide a<br>
VTK object reference across the C++ layer without going through the<br>
Java object layer. (Sorry it is not very clear, but it is quite<br>
difficult to explain.)<br>
<br>
So to solve this problem, you should rewrite the above expression like that.<br>
<br>
vtkDataSetMapper mapper = object.GetMapper();<br>
actor.SetMapper( mapper );<br>
<br>
Hope that helped and please let us know if that solved your problem.<br>
<br>
Seb<br>
<div><div></div><div class="h5"><br>
<br>
On Tue, Nov 23, 2010 at 11:15 PM, Mark Roden &lt;<a href="mailto:mmroden@gmail.com">mmroden@gmail.com</a>&gt; wrote:<br>
&gt; Hi all,<br>
&gt;<br>
&gt; I&#39;m having problems with memory management in java (windows 7, 64 bit and 32<br>
&gt; bit, vtk 5.6).<br>
&gt;<br>
&gt; The application loads ~150mb of dicom images (varies from patient to<br>
&gt; patient), allocates between 1 to 10 binary masks on top of those images, and<br>
&gt; then Does Things, things that include PolyData contours.<br>
&gt;<br>
&gt; Once I&#39;m done with an image, I want to completely wipe all instances of vtk<br>
&gt; and start afresh with a new image.<br>
&gt;<br>
&gt; So, I&#39;m calling<br>
&gt;<br>
&gt; vtkGlobalJavaHash.GC();<br>
&gt;<br>
&gt; But that doesn&#39;t work, even after I delete all windows and data holders.<br>
&gt;<br>
&gt; So, I go ahead and get more aggressive, calling<br>
&gt;<br>
&gt; vtkGlobalJavaHash.DeleteAll();<br>
&gt;<br>
&gt; This call works somewhat better, but appears to leave ~150 mb behind<br>
&gt; (coincidentally, the size of the original image).  When I use the netbeans<br>
&gt; memory profiler at this point, I get no indication that this memory is<br>
&gt; actually in use; I&#39;m seeing the memory allocations via the system resources<br>
&gt; in the task manager.<br>
&gt;<br>
&gt; I then try something a bit more drastic:<br>
&gt;<br>
&gt;     private int DeleteAllVTKObjects(){<br>
&gt;         int deleted = 0;<br>
&gt;         Set entries = vtkGlobalJavaHash.PointerToReference.entrySet();<br>
&gt;         Iterator iter = entries.iterator();<br>
&gt;         while (iter.hasNext()) {<br>
&gt;             Map.Entry entry = (Map.Entry) iter.next();<br>
&gt;             vtkObjectBase obj = (vtkObjectBase) ((WeakReference)<br>
&gt; entry.getValue()).get();<br>
&gt;             if (obj == null) {<br>
&gt;                 // Delete a garbage collected object using the raw C++<br>
&gt; pointer.<br>
&gt;                 long id = ((Long)entry.getKey()).longValue();<br>
&gt;                 vtkObjectBase.VTKDeleteReference(id);<br>
&gt;                 entries.remove(entry);<br>
&gt;                 deleted++;<br>
&gt;             }<br>
&gt;             else if (obj != null){<br>
&gt;                 // Delete a non-garbage collected object.<br>
&gt;                 // We use Delete() which will call the &quot;real&quot; C++ Delete()<br>
&gt;                 // unless Delete() has been called on this Java object<br>
&gt; before.<br>
&gt;                 // Delete() will remove from the map so we don&#39;t have to.<br>
&gt;                 obj.Delete();<br>
&gt;                 deleted++;<br>
&gt;             }<br>
&gt;         }<br>
&gt;         return deleted;<br>
&gt;     }<br>
&gt;<br>
&gt; But that appears to be the same (or no better than)<br>
&gt; vtkGlobalJavaHash.DeleteAll().<br>
&gt;<br>
&gt; So here&#39;s the deal: I&#39;ve got ~140 mb leaking with each image that I open,<br>
&gt; and the profiler indicates that the leak is not in Java.<br>
&gt;<br>
&gt; I&#39;m using the vtkGDCMImageReader to read in images, and this object does not<br>
&gt; (as far as I can see) have a dispose method.  I&#39;m using vtkPolyData objects,<br>
&gt; but again, I&#39;m not seeing dispose methods.  I&#39;m using vtkGDCMPolyDataReader<br>
&gt; and to handle contours, again, no dispose method present.<br>
&gt;<br>
&gt; So right now, I&#39;m thinking that either those particular classes have leaks<br>
&gt; on the C++ side, or some memory is just not getting handled and removed by<br>
&gt; the above calls to vtk.<br>
&gt;<br>
&gt; Are there other ways I can debug this issue?  I want the user to be able to<br>
&gt; open and close as many images as they want, rather than having to restart<br>
&gt; the program every ~10 or so images due to instabilities from the leak.<br>
&gt;<br>
&gt; Also, due to problems I mentioned previously on the list with changes in the<br>
&gt; vtk libraries, I can&#39;t move to the head version of vtk.  If the head version<br>
&gt; has a fix, I can try it, but right now, gdcm and vtk head do not play well<br>
&gt; together at all.  It seems that the vtkStringArrays necessary to read in<br>
&gt; files on the gdcm side are empty when passed through the java layer in 5.7,<br>
&gt; but not in 5.6 (which I discovered through that error &lt;&lt; trick from Monday,<br>
&gt; thanks for that).  I don&#39;t know why that is, but since 5.6 works with gdcm<br>
&gt; git head, that&#39;s the version I have.<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Mark<br>
&gt;<br>
</div></div>&gt; _______________________________________________<br>
&gt; Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
&gt;<br>
&gt; Visit other Kitware open-source projects at<br>
&gt; <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
&gt;<br>
&gt; Please keep messages on-topic and check the VTK FAQ at:<br>
&gt; <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
&gt;<br>
&gt; Follow this link to subscribe/unsubscribe:<br>
&gt; <a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
&gt;<br>
&gt;<br>
</blockquote></div><br>