[Insight-developers] Question about delete on VC++
Miller, James V (Research)
millerjv@crd.ge.com
Mon, 30 Sep 2002 15:53:00 -0400
I think the warning that the compiler reports is for a
class with a non-virtual destructor and and a subclass
with a virtual destructor.
The hierarchy here used STRUCTS as opposed to classes.
So I guessing the compiler didn't warn about structs.
> -----Original Message-----
> From: Joshua Cates [mailto:cates@sci.utah.edu]
> Sent: Monday, September 30, 2002 3:48 PM
> To: Bill Hoffman
> Cc: Miller, James V (Research); 'Jisung Kim'; insight-dev-list
> Subject: RE: [Insight-developers] Question about delete on VC++
>
>
> One of the builds warns about this. I think IRIX.
>
> Josh.
>
> ______________________________
> Josh Cates
> School of Computer Science
> University of Utah
> Email: cates@sci.utah.edu
> Phone: (801) 587-7697
> URL: www.cs.utk.edu/~cates
>
>
> On Mon, 30 Sep 2002, Bill Hoffman wrote:
>
> > Isn't this a warning on some compilers?
> > (Class with virutal table has non-virutal destructors?)
> >
> >
> > -Bill
> >
> >
> > At 03:41 PM 9/30/2002 -0400, Miller, James V (Research) wrote:
> > >I ran the test through Purify. This identified that a leak
> > >occurred. The I spent several hours trying to find why your
> > >memory was not being deallocated. Eventually, I put print
> > >statements in each node type's destructor to make sure they
> > >were being called. As it turned out, the destructors were
> > >never being called because the nodes in the kdtree store pointers
> > >to a kdnode and kdnode did not have a destructor defined. This
> > >meant that the compiler provided its own destructor which by
> > >default is non-virtual.
> > >
> > >Jim
> > >
> > >
> > >
> > >> -----Original Message-----
> > >> From: Jisung Kim [mailto:bahrahm@yahoo.com]
> > >> Sent: Monday, September 30, 2002 2:16 PM
> > >> To: Miller, James V (Research); insight-dev-list
> > >> Subject: RE: [Insight-developers] Question about delete on VC++
> > >>
> > >>
> > >> Thanks, Jim.
> > >>
> > >> Could you tell me how did you found the memory leaks?
> > >> I was experimenting with _CrtDumpMemoryLeaks()
> > >> function. It would be helpful in future.
> > >>
> > >> Thank you very much,
> > >>
> > >> Jisung.
> > >>
> > >> --- "Miller, James V (Research)" <millerjv@crd.ge.com>
> > >> wrote:
> > >> > Jisung,
> > >> >
> > >> > I just fixed the memory leaks in your KdTree.
> > >> >
> > >> > The base kd-node class did not have a "virtual"
> > >> > destructor. When the
> > >> > tree was being deleted, the destructors for "real"
> > >> > kd-nodes was not
> > >> > being called.
> > >> >
> > >> > Jim
> > >> >
> > >> >
> > >> >
> > >> > > -----Original Message-----
> > >> > > From: Jisung Kim [mailto:bahrahm@yahoo.com]
> > >> > > Sent: Friday, September 27, 2002 1:53 PM
> > >> > > To: Jisung Kim; Miller, James V (Research);
> > >> > insight-dev-list
> > >> > > Subject: RE: [Insight-developers] Question about
> > >> > delete on VC++
> > >> > >
> > >> > >
> > >> > > The print out result shows exact match between
> > >> > > addresses of pointer (to nodes) and the order.
> > >> > >
> > >> > >
> > >> > > --- Jisung Kim <bahrahm@yahoo.com> wrote:
> > >> > > > In a same thread.
> > >> > > >
> > >> > > > I will do printing out address of nodes in
> > >> > creation
> > >> > > > and deletion in VC++ too. And let you know the
> > >> > > > result.
> > >> > > >
> > >> > > > --- "Miller, James V (Research)"
> > >> > > > <millerjv@crd.ge.com>
> > >> > > > wrote:
> > >> > > > > Are those in different threads?
> > >> > > > >
> > >> > > > >
> > >> > > > >
> > >> > > > > > -----Original Message-----
> > >> > > > > > From: Jisung Kim [mailto:bahrahm@yahoo.com]
> > >> > > > > > Sent: Friday, September 27, 2002 12:48 PM
> > >> > > > > > To: Miller, James V (Research);
> > >> > insight-dev-list
> > >> > > > > > Subject: RE: [Insight-developers] Question
> > >> > about
> > >> > > > > delete on VC++
> > >> > > > > >
> > >> > > > > >
> > >> > > > > > Yes, the tree was created by the
> > >> > > > > > itkWeightedCenteroidKdTreeGenerator and the
> > >> > > > > deletion
> > >> > > > > > logic is inside of the itkKdTree.
> > >> > > > > >
> > >> > > > > > Is it a problem?
> > >> > > > > >
> > >> > > > > > Thanks,
> > >> > > > > >
> > >> > > > > >
> > >> > > > > > --- "Miller, James V (Research)"
> > >> > > > > <millerjv@crd.ge.com>
> > >> > > > > > wrote:
> > >> > > > > > > Another thought. Is the data allocated in
> > >> > one
> > >> > > > > > > thread and destroyed
> > >> > > > > > > in another thread?
> > >> > > > > > >
> > >> > > > > > >
> > >> > > > > > >
> > >> > > > > > > > -----Original Message-----
> > >> > > > > > > > From: Miller, James V (Research)
> > >> > > > > > > > Sent: Friday, September 27, 2002 12:07
> > >> > PM
> > >> > > > > > > > To: 'Jisung Kim'; insight-dev-list
> > >> > > > > > > > Subject: RE: [Insight-developers]
> > >> > Question
> > >> > > > > about
> > >> > > > > > > delete on VC++
> > >> > > > > > > >
> > >> > > > > > > >
> > >> > > > > > > > Strange. If we were building Dlls, I
> > >> > would
> > >> > > > > say
> > >> > > > > > > that maybe we were
> > >> > > > > > > > allocating nodes in one DLL and
> > >> > deallocating
> > >> > > > > them
> > >> > > > > > > in another DLL.
> > >> > > > > > > > (I think each DLL has its own heap
> > >> > > > > management).
> > >> > > > > > > But since we are
> > >> > > > > > > > not building DLLs, then that is not the
> > >> > > > > problem.
> > >> > > > > > > >
> > >> > > > > > > > Have you run with VC the version that
> > >> > prints
> > >> > > > > out
> > >> > > > > > > all the node
> > >> > > > > > > > allocation and deletions?
> > >> > > > > > > >
> > >> > > > > > > > Is there anything "inside" a node that
> > >> > is
> > >> > > > not
> > >> > > > > > > being deleted?
> > >> > > > > > > > Perhaps a
> > >> > > > > > > > subitem is missing a destructor that
> > >> > needs
> > >> > > > to
> > >> > > > > do
> > >> > > > > > > something
> > >> > > > > > > > that another
> > >> > > > > > > > compiler is providing by default.
> > >> > > > > > > >
> > >> > > > > > > >
> > >> > > > > > > >
> > >> > > > > > > >
> > >> > > > > > > > Friday, September 27, 2002 10:16 AM
> > >> > > > > > > > > To: insight-dev-list
> > >> > > > > > > > > Subject: [Insight-developers] Question
> > >> > > > about
> > >> > > > > > > delete on VC++
> > >> > > > > > > > >
> > >> > > > > > > > >
> > >> > > > > > > > > Hi.
> > >> > > > > > > > >
> > >> > > > > > > > > I have a question for memory
> > >> > deallocation
> > >> > > > in
> > >> > > > > > > VC++.
> > >> > > > > > > > >
> > >> > > > > > > > > Currently, my
> > >> > > > > itkKdTreeBasedKmeansEstimatorTest
> > >> > > > > > > is
> > >> > > > > > > > > leaking memory on VC++ machine. It
> > >> > seems
> > >> > > > > like
> > >> > > > > > > that the
> > >> > > > > > > > > some of the k-d tree nodes has not
> > >> > been
> > >> > > > > deleted.
> > >> > > > > > > > > However, On linux, it didn't have any
> > >> > > > leak.
> > >> > > > > I
> > >> > > > > > > traced
> > >> > > > > > > > > the creation and deletion of nodes by
> > >> > > > print
> > >> > > > > out
> > >> > > > > > > the
> > >> > > > > > > > > address of each nodes. And the result
> > >> > > > shows
> > >> > > > > > > perfect
> > >> > > > > > > > > match between creation and deletion.
> > >> > > > > > > > >
> > >> > > > > > > > > Is there anything more than calling
> > >> > > > "delete"
> > >> > > > > to
> > >> > > > > > > delete
> > >> > > > > > > > > an object. I think I read an article
> > >> > from
> > >> > > > MS
> > >> > > > > > > about
> > >> > > > > > > > > using delete and also assign zero to
> > >> > the
> > >> > > > > pointer
> > >> > > > > > > to
> > >> > > > > > > > > properly delete object in a long time
> > >> > ago.
> > >> > > > > Is it
> > >> > > > > > > the
> > >> > > > > > > > > case? Should I assign zero to the
> > >> > pointer
> > >> > > > > after
> > >> > > > > > > > > calling delete?
> > >> > > > > > > > >
> > >> > > > > > > > > Thank you,
> > >> > > > > > > > >
> > >> > > > > > > > >
> > >> > > > > > > > >
> > >> > > > > > > > > =====
> > >> > > > > > > > > Jisung Kim
> > >> > > > > > > > > bahrahm@yahoo.com
> > >> > > > > > > > > 106 Mason Farm Rd.
> > >> > > > > > > > > 129 Radiology Research Lab., CB# 7515
> > >> > > > > > > > > Univ. of North Carolina at Chapel Hill
> > >> > > > > > > > > Chapel Hill, NC 27599-7515
> > >> > > > > > > > >
> > >> > > > > > > > >
> > >> > > > > > >
> > >> > > > >
> > >> > __________________________________________________
> > >> > > > > > > > > Do you Yahoo!?
> > >> > > > > > > > > New DSL Internet Access from SBC &
> > >> > Yahoo!
> > >> > > > > > > > > http://sbc.yahoo.com
> > >> > > > > > > > >
> > >> > > > >
> > >> > _______________________________________________
> > >> > > > > > > > > Insight-developers mailing list
> > >> >
> > >> === message truncated ===
> > >>
> > >>
> > >> =====
> > >> Jisung Kim
> > >> bahrahm@yahoo.com
> > >> 106 Mason Farm Rd.
> > >> 129 Radiology Research Lab., CB# 7515
> > >> Univ. of North Carolina at Chapel Hill
> > >> Chapel Hill, NC 27599-7515
> > >>
> > >> __________________________________________________
> > >> Do You Yahoo!?
> > >> Yahoo! Health - Feel better, live better
> > >> http://health.yahoo.com
> > >>
> > >_______________________________________________
> > >Insight-developers mailing list
> > >Insight-developers@public.kitware.com
> > >http://public.kitware.com/mailman/listinfo/insight-developers
> >
> > _______________________________________________
> > Insight-developers mailing list
> > Insight-developers@public.kitware.com
> > http://public.kitware.com/mailman/listinfo/insight-developers
> >
>