Concept
How do you deallocate dynamically allocated arrays?
ComputerScienceOne / Using Arrays with Functions
"Once dynamically allocated memory is no longer needed, we should release it so that it can be reused by the program or the operating system. The free() function in the standard library does this for us. All we need to do is provide the pointer to free() and it deallocates the memory block.\n\n1 free(arr);\n\nOnce freed, accessing old memory pointed to by the arr pointer is undefined behavior and may lead to unexpected or fatal results."
Related Ideas
- How do you use and validate a dynamically allocated array?ComputerScienceOne · Dynamic Memory
- What other memory allocation functions and pointer cast options does C provide?ComputerScienceOne · Dynamic Memory
- How does malloc() allocate memory for a dynamic array?ComputerScienceOne · Dynamic Memory
- How does Java dynamically allocate and release memory for arrays?ComputerScienceOne · Using Arrays with Methods
- How does Java dynamically allocate and manage memory for arrays?ComputerScienceOne · Dynamic Memory
- How do you access array elements safely in C?ComputerScienceOne · Basic Usage
- Why use a contiguous memory block for a two-dimensional array?ComputerScienceOne · Contiguous 2-D Arrays
- How do you create and use an array of structures in C?ComputerScienceOne · Arrays of Structures