Bifalgorithm post · Computer science one · Using Arrays with Functions
How do you deallocate dynamically allocated arrays?
How do you deallocate dynamically allocated arrays? (Computer science one · Using Arrays with Functions) — "Once dynamically allocated memory is no longer need…
Ideas in this flowchart
- Release dynamically allocated memory when it is no longer needed
- The memory should no longer be needed before it is released
- Released memory can be reused by the program or the operating system
- The standard-library free() function deallocates the memory block
- Provide the pointer to free() as its argument
- Example: free(arr);
- Accessing memory through arr after it is freed is undefined behavior
- Such access may cause unexpected or fatal results