Ask Your Question
4

What are the issues with using the malloc and free technique?

asked 2023-06-01 22:41:33 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-06-01 23:05:01 +0000

lalupa gravatar image
  1. Memory leaks: If the allocated memory blocks are not deallocated using free(), it can cause memory leaks in the program. This can lead to an eventual and unpredictable crash of the program due to lack of memory.

  2. Fragmentation: Allocating and deallocating memory frequently can result in fragmentation of memory, which means there are small free spaces between the allocated memory blocks, but not enough contiguous space to fulfill larger memory requests.

  3. Overlapping memory: If two or more pointer variables point to the same memory location, it can cause data corruption and unexpected results when reading or writing to memory.

  4. Dangling pointers: If a pointer variable is created to point to a dynamically allocated memory block, and the memory is deallocated using free(), the pointer variable still points to that block of memory, leading to undefined behavior if the pointer is dereferenced.

  5. Memory allocation errors: When allocating memory dynamically, there is a possibility that insufficient memory is available. The program has to handle such cases carefully to avoid unexpected behavior or crashes.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-01 22:41:33 +0000

Seen: 17 times

Last updated: Jun 01 '23