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

后端 未结 5 1665
轮回少年
轮回少年 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:44

    Thank you for all the answers and comments. All have been useful and relevant.

    Any further information is still welcome.


    The following was a comment on my question from Hans Passant:

    Once you start exporting classes from DLLs, compiling with /MD becomes very important. Looks like /MT to me.

    As a result of that, I took a closer look at the linkage setting throughout the project. I found a 'buried' instance of /MT and /MTd that should have been /MD and /MDd, plus some related inconsistencies in other settings.

    Having corrected those, no assertion is now thrown, and the code appears to be behaving correctly.


    Here are some of the things to check when experiencing crashes or assertion failures at execution leaves scopes and destructors are called. Ensure that throughout all projects (including dependencies) and in all configurations (especially in the problematic one):

    (Here the *.vcproj paths are relative to .)

    • The correct runtime is selected in C/C++ | Code Generation | Runtime Library ;
    • Appropriate definitions (if any) are made in C/C++ | Preprocessor | Preprocessor Definitions especially relating to the use of static versus dynamic libraries (e.g. _STLP_USE_STATIC_LIB versus _STLP_USE_DYNAMIC_LIB for STLport);
    • Appropriate versions of libraries are selected in Linker | Input | Additional Dependencies especially relating to static runtime libraries versus 'wrappers' for DLLs (e.g. stlport_static.lib versus stlport.N.M.lib).

    Interestingly, the scalar 'flavour' of delete I'd expect still does not appear to be being called (the breakpoint is never hit). That is, I still only see the vector deleting destructor. Therefore, that may have been a 'red herring'.

    Perhaps this is just a Microsoft implementation issue, or perhaps there's still some other subtlety I've missed.

提交回复
热议问题