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