How to create a memory leak in C++?

前端 未结 10 1361
没有蜡笔的小新
没有蜡笔的小新 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:06

    A memory leak occurs when you call new without calling a corresponding delete later. As illustrated in this sample code:

    int main() {
        // OK
        int * p = new int;
        delete p; 
    
        // Memory leak
        int * q = new int;
        // no delete
    }
    

提交回复
热议问题