<br>
- return stripper.GetOutput(); // Maybe it is OK but I'm not sure...<br><br>This looks like it's just a dangerous line altogether. Removing it seems to have brought the leak down to about ~10-~40 mb per instance, which could just be noise since I can't directly profile things.<br>
<br>Thanks much for the help!<br>Mark<br><br><div class="gmail_quote">On Wed, Nov 24, 2010 at 1:24 PM, 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;">This is OK<br>
- renWin.GetRenderer().AddActor(outlineActor);<br>
<div class="im">- for (int j=0; j<cell.GetNumberOfPoints()-1; j++)<br>
<br>
</div>This is NOT OK<br>
- stripper.SetInput(marching.GetOutput());<br>
- return stripper.GetOutput(); // Maybe it is OK but I'm not sure...<br>
<br>
Accessing a value is ok but asking a vtkObject to give a reference to<br>
one of its internal to another vtkObject is not OK if you don't<br>
provide a temporary Java object inbetween.<br>
<br>
Seb<br>
<div><div></div><div class="h5"><br>
On Wed, Nov 24, 2010 at 4:14 PM, Mark Roden <<a href="mailto:mmroden@gmail.com">mmroden@gmail.com</a>> wrote:<br>
> Hi Sebastien,<br>
><br>
> I've made the changes, as in:<br>
><br>
><br>
> vtkPolyData marchingoutput = marching.GetOutput();<br>
><br>
> stripper.SetInput(marchingoutput);<br>
><br>
> instead of<br>
><br>
> stripper.SetInput(marching.GetOutput());<br>
><br>
> But in order for this to be effective, do I need to correct lines like<br>
><br>
> renWin.GetRenderer().AddActor(outlineActor);<br>
><br>
> Should that be split, or can I continue to have multiple command stacked<br>
> like that? Could the renWin.GetRenderer() leak in the above line?<br>
><br>
> How about a method that returns something like<br>
><br>
> return stripper.GetOutput();<br>
><br>
> Will that leak?<br>
><br>
> or<br>
><br>
> for (int j=0; j<cell.GetNumberOfPoints()-1; j++)<br>
><br>
> I have a lot of inlining (if that's the proper term in this context) in my<br>
> code. If the only way to solve this problem is to have each individual vtk<br>
> call be its own call, that's a pretty big refactor. So are there certain<br>
> rules I can use to avoid this? If it's just making sure that one output<br>
> doesn't directly go into another input, that's straightforward. Buf it it's<br>
> 'every time a function with .get' is called, then I need to fix quite a bit<br>
> more.<br>
><br>
> This approach does look like it's pulled the leak down somewhat, but not<br>
> entirely.<br>
><br>
> Mark<br>
><br>
><br>
><br>
> On Wed, Nov 24, 2010 at 12:56 PM, Sebastien Jourdain<br>
> <<a href="mailto:sebastien.jourdain@kitware.com">sebastien.jourdain@kitware.com</a>> wrote:<br>
>><br>
>> Hi Mark,<br>
>><br>
>> I agree it is a common habit in Java. But this problem ONLY if object<br>
>> is a vtkObject. If it's one of your Java object, this is not a<br>
>> problem.<br>
>><br>
>> Seb<br>
>><br>
>> On Wed, Nov 24, 2010 at 3:11 PM, Mark Roden <<a href="mailto:mmroden@gmail.com">mmroden@gmail.com</a>> wrote:<br>
>> > Hi Sebastian,<br>
>> ><br>
>> > Thanks for giving me a place to start. I'll take a look at my various<br>
>> > pipelines and see where/if I'm doing things like that. I probably am,<br>
>> > since<br>
>> > 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>
>> > On Wed, Nov 24, 2010 at 9:37 AM, Sebastien Jourdain<br>
>> > <<a href="mailto:sebastien.jourdain@kitware.com">sebastien.jourdain@kitware.com</a>> wrote:<br>
>> >><br>
>> >> 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<br>
>> >> 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>
>> >><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<br>
>> >> > 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<br>
>> >> > images,<br>
>> >> > 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<br>
>> >> > of<br>
>> >> > 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<br>
>> >> > 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<br>
>> >> > netbeans<br>
>> >> > memory profiler at this point, I get no indication that this memory<br>
>> >> > is<br>
>> >> > actually in use; I'm seeing the memory allocations via the system<br>
>> >> > 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 =<br>
>> >> > 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<br>
>> >> > 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++<br>
>> >> > Delete()<br>
>> >> > // unless Delete() has been called on this Java<br>
>> >> > object<br>
>> >> > before.<br>
>> >> > // Delete() will remove from the map so we don't have<br>
>> >> > 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<br>
>> >> > 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<br>
>> >> > does<br>
>> >> > not<br>
>> >> > (as far as I can see) have a dispose method. I'm using vtkPolyData<br>
>> >> > objects,<br>
>> >> > but again, I'm not seeing dispose methods. I'm using<br>
>> >> > 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<br>
>> >> > leaks<br>
>> >> > on the C++ side, or some memory is just not getting handled and<br>
>> >> > removed<br>
>> >> > by<br>
>> >> > the above calls to vtk.<br>
>> >> ><br>
>> >> > Are there other ways I can debug this issue? I want the user to be<br>
>> >> > able<br>
>> >> > to<br>
>> >> > open and close as many images as they want, rather than having to<br>
>> >> > restart<br>
>> >> > the program every ~10 or so images due to instabilities from the<br>
>> >> > leak.<br>
>> >> ><br>
>> >> > Also, due to problems I mentioned previously on the list with changes<br>
>> >> > in<br>
>> >> > the<br>
>> >> > vtk libraries, I can't move to the head version of vtk. If the head<br>
>> >> > version<br>
>> >> > has a fix, I can try it, but right now, gdcm and vtk head do not play<br>
>> >> > well<br>
>> >> > together at all. It seems that the vtkStringArrays necessary to read<br>
>> >> > in<br>
>> >> > files on the gdcm side are empty when passed through the java layer<br>
>> >> > in<br>
>> >> > 5.7,<br>
>> >> > but not in 5.6 (which I discovered through that error << trick from<br>
>> >> > Monday,<br>
>> >> > thanks for that). I don't know why that is, but since 5.6 works with<br>
>> >> > gdcm<br>
>> >> > git head, that's the version I have.<br>
>> >> ><br>
>> >> > Thanks,<br>
>> >> > Mark<br>
>> >> ><br>
>> >> > _______________________________________________<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>
>> ><br>
>> ><br>
><br>
><br>
</div></div></blockquote></div><br>