Hi all,<br><br>I'm having problems with memory management in java (windows 7, 64 bit and 32 bit, vtk 5.6).<br><br>The application loads ~150mb of dicom images (varies from patient to patient), allocates between 1 to 10 binary masks on top of those images, and 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 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 (coincidentally, the size of the original image). When I use the netbeans memory profiler at this point, I get no indication that this memory is actually in use; I'm seeing the memory allocations via the system resources 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) entry.getValue()).get();<br> if (obj == null) {<br>
// Delete a garbage collected object using the raw C++ 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 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) vtkGlobalJavaHash.DeleteAll(). <br><br>So here's the deal: I've got ~140 mb leaking with each image that I open, 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 (as far as I can see) have a dispose method. I'm using vtkPolyData objects, but again, I'm not seeing dispose methods. I'm using vtkGDCMPolyDataReader and to handle contours, again, no dispose method present. <br>
<br>So right now, I'm thinking that either those particular classes have leaks on the C++ side, or some memory is just not getting handled and removed by the above calls to vtk.<br><br>Are there other ways I can debug this issue? I want the user to be able to open and close as many images as they want, rather than having to restart 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 vtk libraries, I can't move to the head version of vtk. If the head version has a fix, I can try it, but right now, gdcm and vtk head do not play well together at all. It seems that the vtkStringArrays necessary to read in files on the gdcm side are empty when passed through the java layer in 5.7, but not in 5.6 (which I discovered through that error << trick from Monday, thanks for that). I don't know why that is, but since 5.6 works with gdcm git head, that's the version I have.<br>
<br>Thanks,<br>Mark<br>