If you know which class you are looking for, you could modify the vtkObjectBaseBacktrace function so that it filters by class name (the char* type argument), but just be aware that when vtkObjectBaseBacktrace is called from object constructors the class name is not known.<br>
<br>Pat<br><br><div class="gmail_quote">On Wed, Jan 20, 2010 at 10:55 AM, Arnaud Gelas <span dir="ltr"><<a href="mailto:Arnaud_Gelas@hms.harvard.edu">Arnaud_Gelas@hms.harvard.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="">I have just started one application with this piece of code, and I see what you mean by "ridiculous amount of stack traces"...<div><br></div><div>You're right, you need to first identify the problem before using it...</div>
<div><br></div><font color="#888888"><div>Arnaud</div></font><div><div></div><div class="h5"><div><br><div><div><div>On Jan 20, 2010, at 10:21 AM, Moreland, Kenneth wrote:</div><br><blockquote type="cite"><div> <font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;">Because that would be insane.  I always turn on VTK_DEBUG_LEAKS in my development builds (and I highly encourage anyone developing with VTK to do the same).  Always having this code enabled would mean I would get a ridiculous amount of stack traces whenever I ran anything.<br>
 <br> This is a handy tool when you are looking for a specific problem.  If you have not identified any problem, it just serves to hide anything important.<br> <br> -Ken<br> <br> <br> On 1/20/10 8:07 AM, "Arnaud Gelas" <<a href="http://Arnaud_Gelas@hms.harvard.edu" target="_blank">Arnaud_Gelas@hms.harvard.edu</a>> wrote:<br>
 <br> </span></font><blockquote><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;">Hi Pat,<br> <br> Sorry for the late reply, I was out of town...<br> <br> This sounds great! I'll give it a try!<br>
 <br> I was wondering why not adding/enabling this code when VTK_DEBUG_LEAKS is ON, and user uses gcc?<br> <br> Thanks,<br> Arnaud<br> <br> On Jan 18, 2010, at 7:07 PM, pat marion wrote:<br> <br> </span></font><blockquote>
<font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;">Hi,<br> <br> I don't find valgrind to be very useful for debugging vtk leaks because valgrind only reports where the memory was allocated.  A vtkObject leaks because someone holds a reference to it and does not release the reference.  Knowing where the object was allocated doesn't necessarily give you any clues.<br>
  <br> Here is a patch by Brad King that will print a stack trace each time a vtkObject's reference count is increased or decreased.  The output is very verbose, but if you know what you are looking for this can give you the clues you need to track down the leak-<br>
  <br> Brad King on 12/23/09-<br> <br> This hacks up vtkObjectBase to report a stack trace (on Linux) for every<br>  constructor, Register, or UnRegister call on VTK objects.  We include<br>  the object address (pointer value) for identification.  While very<br>
  verbose, the output produced with this change can be used to find the<br>  source of leaked objects.<br>  ---<br>   Common/vtkObjectBase.cxx |   27 +++++++++++++++++++++++++++<br>   1 files changed, 27 insertions(+), 0 deletions(-)<br>
  <br>  diff --git a/Common/vtkObjectBase.cxx b/Common/vtkObjectBase.cxx<br>  index de8c1cf..1b71fb7 100644<br>  --- a/Common/vtkObjectBase.cxx<br>  +++ b/Common/vtkObjectBase.cxx<br>  @@ -19,6 +19,10 @@<br>  <br>   #include <vtksys/ios/sstream><br>
  <br>  +static inline<br>  +void vtkObjectBaseBacktrace(<br> vtkObjectBase* obj, const char* op,<br>  +                            const char* type);<br>  +<br>   #define vtkBaseDebugMacro(x)<br>  <br>   class vtkObjectBaseToGarbageCollectorFriendship<br>
  @@ -63,6 +67,7 @@ ostream& operator<<(ostream& os, vtkObjectBase& o)<br>   // to zero.<br>   vtkObjectBase::vtkObjectBase()<br>   {<br>  +  vtkObjectBaseBacktrace(this, "Construct", "vtkObjectBase");<br>
    this->ReferenceCount = 1;<br>    // initial reference count = 1 and reference counting on.<br>   }<br>  @@ -229,6 +234,7 @@ void vtkObjectBase::PrintRevisions(ostream& os)<br>   //----------------------------------------------------------------------------<br>
   void vtkObjectBase::RegisterInternal(vtkObjectBase*, int check)<br>   {<br>  +  vtkObjectBaseBacktrace(this, "Register", this->GetClassName());<br>    // If a reference is available from the garbage collector, use it.<br>
    // Otherwise create a new reference by incrementing the reference<br>    // count.<br>  @@ -242,6 +248,7 @@ void vtkObjectBase::RegisterInternal(vtkObjectBase*, int check)<br>   //----------------------------------------------------------------------------<br>
   void vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int check)<br>   {<br>  +  vtkObjectBaseBacktrace(this, "UnRegister", this->GetClassName());<br>    // If the garbage collector accepts a reference, do not decrement<br>
    // the count.<br>    if(check && this->ReferenceCount > 1 &&<br>  @@ -274,3 +281,23 @@ void vtkObjectBase::ReportReferences(vtkGarbageCollector*)<br>   {<br>    // vtkObjectBase has no references to report.<br>
   }<br>  +<br>  +//----------------------------------------------------------------------------<br>  +#include <execinfo.h><br>  +static inline<br>  +void vtkObjectBaseBacktrace(vtkObjectBase* obj, const char* op,<br>
  +                            const char* type)<br>  +{<br>  +  static const int max_depth = 100;<br>  +  void* calls[max_depth];<br>  +  int depth = backtrace(calls, max_depth);<br>  +  if(char** symbols = backtrace_symbols(calls, depth))<br>
  +    {<br>  +    fprintf(stderr, "%s %p %s\n", op, obj, type);<br>  +    for(int i = 0; i < depth; ++i)<br>  +      {<br>  +      fprintf(stderr, "  %s\n", symbols[i]);<br>  +      }<br>  +    free(symbols);<br>
  +    }<br>  +}<br> <br> <br> On Fri, Jan 15, 2010 at 9:23 AM, Mathieu Malaterre <<a href="http://mathieu.malaterre@gmail.com" target="_blank">mathieu.malaterre@gmail.com</a>> wrote:<br> </span></font><blockquote><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;"> On Thu, Jan 14, 2010 at 11:50 PM, Arnaud Gelas<br>
  <br> <<a href="http://arnaud_gelas@hms.harvard.edu" target="_blank">arnaud_gelas@hms.harvard.edu</a>> wrote:<br>  <br> > Hi Guys,<br>  ><br>  > I really liked the idea of VTK_DEBUG_LEAKS to know exactly which objects<br>
  > were not deleted (name of objects forgot to be deleted and number of<br>  > instances)<br>  > But the way it is right now it is quite difficult to get a clue on WHERE we<br>  > forgot to delete (maybe due to the lack of hierarchical information?).<br>
  ><br>  > Is there anyway to improve it by adding some additional information to track<br>  > where leaks exactly come from?<br>  <br>  <br> I usually sort them by count number. The idea is that if a vtk object<br>
  with a count of 1 remains, it 'most of the time' means this is the<br>  toplevel vtk object that uses others.<br>  <br>  If you are a C#/Java/C++0xWithGarbageCollector guy, then simply switch<br>  to vtkSmartPointer<> coding style convention.<br>
  <br>  2cts<br>  --<br>  <font color="#888888">Mathieu<br>  <br> </font>_______________________________________________<br>  Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a> <<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>> <br>
  <br>  Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>  <br>  Follow this link to subscribe/unsubscribe:<br>
  <a href="http://www.vtk.org/mailman/listinfo/vtk-developers" target="_blank">http://www.vtk.org/mailman/listinfo/vtk-developers</a><br>  <br>  <br> </span></font></blockquote><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;"><br>
 </span></font></blockquote><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;"><br> <br> </span></font></blockquote><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;"><br>
 </span></font><font size="2"><font face="Consolas, Courier New, Courier"><span style="font-size: 10pt;"><br>    ****      Kenneth Moreland<br>     ***      Sandia National Laboratories<br> ***********  <br> *** *** ***  email: <a href="http://kmorel@sandia.gov" target="_blank">kmorel@sandia.gov</a><br>
 **  ***  **  phone: (505) 844-8919<br>     ***      web:   <a href="http://www.cs.unm.edu/%7Ekmorel" target="_blank">http://www.cs.unm.edu/~kmorel</a><br> </span></font></font><font face="Calibri, Verdana, Helvetica, Arial"><span style="font-size: 11pt;"><br>
 </span></font> </div>  </blockquote></div><br></div></div></div></div></div></blockquote></div><br>