digitalmars.D - deleting objects caused "Finalization error" when threading
- Huang Guan <gdxxhg gmail.com> Jun 29 2008
- Frank Benoit <keinfarbton googlemail.com> Jun 29 2008
- "Vladimir Panteleev" <thecybershadow gmail.com> Jun 29 2008
- Sean Kelly <sean invisibleduck.org> Jun 30 2008
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?
Jun 29 2008
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.
Jun 29 2008
On Sun, 29 Jun 2008 12:18:37 +0300, Frank Benoit <keinfarbton 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. -- Best regards, Vladimir mailto:thecybershadow gmail.com
Jun 29 2008
== Quote from Vladimir Panteleev (thecybershadow gmail.com)'s articleOn Sun, 29 Jun 2008 12:18:37 +0300, Frank Benoit <keinfarbton 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.
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
Jun 30 2008








Sean Kelly <sean invisibleduck.org>