Why is vector deleting destructor being called as a result of a scalar delete?

后端 未结 5 1667
轮回少年
轮回少年 2020-12-31 11:23

I have some code that is crashing in a large system. However, the code essentially boils down to the following pseudo-code. I\'ve removed much of the detail, as I have tried

5条回答
  •  心在旅途
    2020-12-31 11:34

    In my case, it's that the wrong 'flavour' of deleting destructor appears to be being applied: i.e. vector rather than scalar.

    That's not the problem here. As per the pseudocode in Mismatching scalar and vector new and delete, the scalar deleting destructor simply calls through to the vector deleting descructor with a flag saying "Do scalar destruction rather than vector destruction".

    Your actual problem, as noted by other posters, is you're allocating on one heap, and deleting on another. The clearest solution is to give your classes overloads of operator new and operator delete, as I described in an answer to a similar question: Error deleting std::vector in a DLL using the PIMPL idiom

提交回复
热议问题