I have been trying to learn the details of how the .NET GC works. One of the things that I guess it does is compact the heaps when memory fragmentation is over some threshold. Now my understanding of memory fragmentation is that when you have a different size objects, they don’t necessarily fit nicely in the available memory ranges on the heap, so defragmentation is needed (in .NET it compacts them, which makes sense) to make sure when you allocate an object there is a spot to put it.
Now my question is, does this mean reference values need to be reassigned when compacting occurs? In other words, once you get a reference, the address that it points to can’t be considered ‘constant’. The compacting cycle will need to move the data right? This would mean the address it’s pointed to should be treated in the same manner as the collection itself…practically non-deterministic in the general case (I know it’s technically deterministic). Is this a correct read of the .NET garbage collection?
Am I thinking of this correctly?