Shrinking the heap at runtime

Would it be complicated to add the possibility of shrinking the heap at runtime? My use case is that I create a large data structure which is first optimized for updates, and then I optimize the structure for reads (I do this once at start-up). The structure for reads is much smaller than the one for updates, but the program continues to run with the size of the heap it needed during the update phase. My program needs 1GB of RAM during the update phase, but afterwards it should be fine with 500MB (the heap size after garbage collection is 400MB; this gives a 100MB margin).

I'm thinking we might be able to force the garbage collector to run and afterwards change the heap settings?

An alternative I see would be copying the created data structure to a string and store that on disk, so that I don't have to recreate it on every run, but using GraphCopy I would still need the whole data structure + its string representation at the same time in memory. If we had a version of GraphCopy that worked on files this would work better. If you have other ideas I'm also happy to hear them.