Tuesday, December 09, 2008

Symbian: Destructor of a global object is not called


It's been a week since I started to port some code here to Symbian platform. The development for Symbian is kind of new experience for me. I did some Windows Mobile development before that is quite different and the porting was easier across Windows platforms.

Today I finished the first part of the code for Symbian and was looking into problem that was causing a memory leak in my unit tester application with ALLOC panic in the main thread at the exit in the Debug mode due to the __UHEAP_MARKEND; in the end of E32Main routine.

After some debugging I found that the application code was having a global instance and the destructor of the instance was never called on the application exit. This was quite odd and the only possible fix for this was to call destructor explicitly at the end of the program execution. The thread panic can be "fixed" by removing the __UHEAP_MARKEND; thus eliminating the heap check at the exit, but this just allows to hide the problem. Obviously the memory will be recycled after the process terminated, but if you rely on some code logic that needs to be run at the time the object gets destroyed you are out of luck.

I did some search online and found that this problem is known and documented:
http://wiki.forum.nokia.com

I like how the solution sentence was phrased:

Solution
No known solution. At the moment, it is advised not to perform any important operations using destructors.

To me this is kind one of fundamental thing to be able to rely on the destructors being called and at this point I'm curious if this was done intentionally or if this is just a bug. If anyone reading this post can shed more light on this , please let me know.

Best Wishes,
Alex

No comments: