
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
What is Memory Leak in C/C++?
The memory leak occurs, when a piece of memory which was previously allocated by the programmer. Then it is not deallocated properly by programmer. That memory is no longer in use by the program. So that place is reserved for no reason. That’s why this is called the memory leak.
For the memory leak, some block of memory may have wasted. If the system has enough memory, in that case also this may slow down the performance.
Example
void my_func() { int *data = new int; *data = 50; }
Here the problem is *data pointer is never deleted, so memory is wasted.
Example
#include <stdio.h> main(void) { auto int my_fun(); my_fun(); printf("Main Function\n"); int my_fun() { printf("my_fun function\n"); } printf("Done"); }
Output
my_fun function Main Function Done
- Related Articles
- What is DNS Leak (IP Leak)?
- What is Dynamic Memory Allocation in C?
- How can Detached DOM elements cause memory leak in JavaScript?
- How can closures cause memory leak and how to prevent it?
- What are memory operations in C language?
- CSF Leak (Cerebrospinal Fluid Leak)
- What is a Web Real-Time Communication (WebRTC)Leak?
- What do you mean by Dynamic memory allocation in C programming?
- What do you mean by static memory allocation in C programming?
- Memory Layout of C Programs
- Memory representation of Binomial Heap in C++
- What is Control Memory?
- What is Virtual Memory?
- What is Auxiliary Memory?
- What is Associative Memory?

Advertisements