new() without delete() is Undefined Behavior or me

2019-01-09 19:00发布

Possible Duplicate:
Are memory leaks “undefined behavior” class problem in C++?

Never calling delete or delete[] on address returned by new or new [] resp in a C++ program is an Undefined Behavior or merely a memory leak?

References from the Standard(if any) are welcome.
This came up in one of the comments here & I am just a bit confused about it.

7条回答
倾城 Initia
2楼-- · 2019-01-09 19:49

Referring to [basic.stc.dynamic.deallocation] (aka 3.7.4.2 in n3337) there are only 4 paragraphs.

  1. operator delete and operator delete[] should be either class members or in global scope
  2. Precisions on the valide signatures of operator delete and operator delete[]
  3. Precisions on which delete can be used for deallocation, depending on which new was used for allocation
  4. Precisions on the possible arguments value and effects of the call (ie the pointers to this storage are now invalid)

There is absolutely no note here on what would happen if storage is allocated but never released.

I don't think that the Standard concerns itself with this, so it is more unspecified rather than undefined.

查看更多
登录 后发表回答