Discuss two main approaches to identify free memory area in a heap.
Two popular systems to identify free memory areas as a result of allocation and de-allocations in a heap are:
1. Reference count: the system relates a reference count along with each memory area to specify the number of its active users. Such number is incremented while a user accesses that area and decrements while user stops utilizing that. The area is free if the reference counts drops to zero. Such scheme is very easy to implement though incurs incremental overheads.
2. Garbage collection: In this system two passes are made over the memory to know unused areas. In the first pass this traverses all pointers pointing to assigned areas and marks the memory areas which are in use. The second pass determines all unmarked areas and declares all to be free. The garbage collection over-heads are not incremental. They are incurred all time the system runs out of free memory to assign to fresh requests.