[vtk-developers] FW: [vtkusers] Resource Leak with VTK + BCB6 (vtkTimerLog)

John Biddiscombe john.biddiscombe at mirada-solutions.com
Tue Aug 12 12:00:59 EDT 2003


Redirected to developers...Is there any automatic timer log cleaning agent hidden away? In my own code I tend to add a #pragma exit (borland syntax) to some cleanup function that would call TimerLog::DeallocateLog.

Is there a precedent in vtk anywhere that can be cloned to cleanup the leak in vtkTimerLog

JB


-----Original Message-----
From: Xianjin Yang [mailto:Yang at AGIUSA.COM]
Sent: 12 August 2003 16:51
To: John Biddiscombe; Mathieu Malaterre
Cc: vtkusers at vtk.org
Subject: RE: [vtkusers] Resource Leak with VTK + BCB6 (vtkTimerLog)


Hi John,

The vtkTimerLog-related leak problem has been solved by following your
instructions below. Like what you said, I hope there is an automatic and
invisible way to handle this.

Thanks a lot

Yang

-----Original Message-----
From: John Biddiscombe [mailto:john.biddiscombe at mirada-solutions.com] 
Sent: Tuesday, August 12, 2003 5:32 AM
To: Mathieu Malaterre
Cc: Xianjin Yang; vtkusers at vtk.org
Subject: RE: [vtkusers] Resource Leak with VTK + BCB6


Hmmm....I see.

Looking at vtkTimerLog.cxx and .h I see that AllocateLog allocates some memory
but there's no cleanup in the destructor - as it's a static structure it may be
reused at different time. I think it'd be best to add a static cleanup method in
there that can be called just before program exit by the user.

try this

add to vtkTimerLog.h

static void DeallocateLog();


add to vtkTimerLog.cxx

void DeallocateLog() 
{
  if (vtkTimerLog::TimerLog != NULL)
    {
    delete [] vtkTimerLog::TimerLog;
    }
  vtkTimerLog::TimerLog = NULL;
}

and at some point when your program is about to exit and no more vtk objects are
going to be used, do a vtkTimerLog::DeallocateLog(); call. This will free up the
memory. Is this only used when some debugging is enabled, or is it always used?

If this fix cures the problem, then I guess it can be added, but there ought to
be some invisible timerlog management that does this automatically...

JB



More information about the vtk-developers mailing list