How to create a memory leak in C++?

前端 未结 10 1323
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 00:35

I was just wondering how you could create a system memory leak using C++. I have done some googling on this but not much came up, I am aware that it is not really feasible t

10条回答
  •  天命终不由人
    2020-12-30 01:05

    #include 
    
    void main(){
    
    for(int i = 0; i < 1000; i++)
    
    double* ptr = (double*)malloc(1000000*sizeof(double))
    
    //free(ptr);
    
    ptr = NULL;
    
    }
    

    note : the hashed line of code caused a memory leak while the process allocated it and did't return it back to the OS

提交回复
热议问题