deleting objects caused "Finalization error" when threading

Sean Kelly sean at invisibleduck.org
Mon Jun 30 14:10:08 PDT 2008


== Quote from Vladimir Panteleev (thecybershadow at gmail.com)'s article
> On Sun, 29 Jun 2008 12:18:37 +0300, Frank Benoit
> <keinfarbton at googlemail.com> wrote:
> > Huang Guan schrieb:
> >> Hi, I am still writing my Web Server program and I still can not go
> >> through the problems that might be caused by GC. I often catch the
> >> exception "Finalization error" when a connection is being deleted.  As
> >> I have been accustomed to deleting objects when I don't use it( Want to
> >> release memory quickly ), I wrote many "delete" statements. I think the
> >> problem above happens when a thread is deleting a object, but which is
> >> at the moment used by another thread, then it causes the "Finalization
> >> error" exception.  I don't know whether I am right or not.
> >> But as I replaced the "delete obj" instead of "obj = null", the problem
> >> seldom happened.
> >>  Do you have any ideas?
> >>
> >
> > The 'Finalization error' is thrown, if a destructor has thrown an
> > exception, which is not allowed.
> Thus, it's likely that you missed one or more delete statements in your
> code, then the garbage collector picked up an object and its children
> (objects to which only the parent object has references to). Since the
> order the GC destroys unreferenced objects is undetermined, you're
> probably trying to manually delete a child in your parent destructor's
> class, when that child has already been deleted by the GC.

FinalizeException should link to the originating exception object, and
both error messages should be displayed when the program exits. Look
at the second message for an idea of where the problem is.  That said,
it's actually good to hear that people are seeing FinalizeExceptions,
because it means they're doing their job :-)


Sean



More information about the Digitalmars-d mailing list