Book a Demo

Author Topic: Warning: C++ code gen of interfaces - mem leak!  (Read 2603 times)

Barry_Pearce

  • EA User
  • **
  • Posts: 70
  • Karma: +0/-0
    • View Profile
Warning: C++ code gen of interfaces - mem leak!
« on: July 02, 2004, 01:37:11 pm »
Hi all,

here is a serious issue we picked up on today....

Who is affected?
Anyone code generating C++, and lets EA code generated default constructors and destructors.

What is the problem?
If you let EA code gen the destructors you will have no doubt made them virtual (mad if you didnt....mad that it wasnt built into the language but there you go)..
However, EA does not generate default constructors or destructors for interfaces - these are the very things you are likely to inherit from....

If you destroy an object through a pointer to one of these interfaces, and the interface is a base class - then your derived class destructors will NOT be called.

OK What can we do?
There are 2 code gen templates (CGT) that need altering...ClassImpl and ClassBody. If you cant work out the fix yourself let me know and ill happily supply the XML template that you can import to get the right stuff out.

Just drop me an email via the private message system on this forum - this can be done by clicking on my name! Ill keep an eye open regularly over the next few days for anyone wanting help...

The basic idea behind the fix is that all interfaces and any class steretyped as an interface that does not already have a constructor/virtual destructor is given an inline one in the header file. This will ensure the v-table is correctly setup for all your derived classes and destruction will occur correctly.

Any Q just shout.
Barry
« Last Edit: July 02, 2004, 01:42:45 pm by Barry_Pearce »

Barry_Pearce

  • EA User
  • **
  • Posts: 70
  • Karma: +0/-0
    • View Profile
Re: Warning: C++ code gen of interfaces - mem leak
« Reply #1 on: July 05, 2004, 02:20:22 pm »
Quick and efficient Sparx have already confirmed this will be fixed in build 731.  8)