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
Feed/

How do you deallocate dynamically allocated arrays?

No cover

Channel

Computer science one

1 page

"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."

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.