问题
If I know a certain value is likely to survive its first encounter with the garbage collector, is there some way to let GHC know, so it can just allocate it directly somewhere outside the nursery? For instance, if I'm building up a large structure out of a bunch of smaller pieces, I know each piece will last at least until the whole structure is complete.
回答1:
In the GHC garbage collector there are no hooks for hinting at the generation an object should be allocated to. However, you might be able to exploit the operational behavior in a couple of ways:
depending on the data type, you may be able to exploit the pinned object region to bypass the generational stages altogether.
exploit eager promotion by ensuring your long lived object is pointed out by something itself long lived...
make the data into a CAF and bypass dynamic allocation altogether.
来源:https://stackoverflow.com/questions/27630833/is-it-possible-to-skip-the-nursery