📝Using mprotect none to catch GC bugs

If you develop a compacting/copying garbage collector, it’s helpful to use page protection to detect bugs earlier.

After you move values out of a page, you can use mprotect to set permissions to none—even reading from a page is forbidden. Now, instead of reading values from invalid memory, processing them, and crashing down the line, the app will crash as soon as it tries to access the old memory.

If you see SIGSEGV: address access protected, you know some pointer didn’t get updated by the GC.