c++ - why is a scalar deleting destructor being called as a result of vector delete on Windows? -


i have code leaking on windows. runs fine on many unix platforms , leak occurs on windows. binary consists of exe, 1 dll , 2 static libs. exe links both dll , static libs, while static libs link dll well. leak occurs in exe code when instead of calling vector deleting destructor, reason scalar deleting destructor called. results in first object in array deleted while rest of array stays in memory.

the leaking pseudo-code looks this:

class myclassfromexe : public mybaseclassfromdll {   public:     classfromdll* m_arr;      myclassfromexe(unsigned int size)       {       m_arr = new classfromdll[size];     }      ~myclassfromexe()      {       delete [] m_arr;     } };  void func() {   myclassfromexe obj(3); } 

when func() finishes , destructor called see destructor of first object in m_arr called. debugger see done scalar deleting destructor , not vector deleting destructor. explains why first object destroyed. need understand why scalar deleting destructor called when delete [] used???

i found thread - why vector deleting destructor being called result of scalar delete?. followed suggestions there , made sure modules compiled /md.

important notice when dll contains classfromdll static library , not dll, worked fine. leak started when static library changed dll. while program leaks in release mode, crashes in debug mode on delete [] m_arr. crash occurs in dbgdel.cpp line 52 - _block_type_is_valid(phead->nblockuse).

on unix platforms lib shared lib , expected vector deleting destructor called there , there no leak. problem vc compiler? or maybe other settings of projects need changed? i'm using vc2003.

thank in advance!

this old problem in vc++ regarding dlls , object-arrays. cause incorrect compiler optimization explained microsoft.

http://support.microsoft.com/kb/121216/en-us

better use stl-containers dont have problem due use of allocator.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -