Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

memory leak in cpp

// Program with memory leak
#include <bits/stdc++.h>
using namespace std;
 
// function with memory leak
void func_to_show_mem_leak()
{
    int* ptr = new int(5);
 
    // body
 
    // return without deallocating ptr
    return;
}
 
// driver code
int main()
{
 
    // Call the function
    // to get the memory leak
    func_to_show_mem_leak();
 
    return 0;
}
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #memory #leak #cpp
ADD COMMENT
Topic
Name
4+4 =