Is not calling delete on a dynamically allocated object always a memory leak?

前端 未结 6 1518
醉话见心
醉话见心 2020-12-07 02:08

From the discussion started here, I\'d like to know whether the following code has a memory leak:

int main()
{
   new int();
   //or
   int* x = new int();
          


        
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-07 02:32

    Yes, there is a leak of 4 bytes because memory allocated by new is not deleted and during the life of the application it is a leak.

    From this link:

    http://www.yolinux.com/TUTORIALS/C++MemoryCorruptionAndMemoryLeaks.html

    Memory leak description: Memory is allocated but not released causing an application to consume memory reducing the available memory for other applications and eventually causing the system to page virtual memory to the hard drive slowing the application or crashing the application when than the computer memory resource limits are reached. The system may stop working as these limits are approached.

提交回复
热议问题