You can guarantee that the object will not be assembled by referencing it from the root of the GC, but not by the fact that it is not processed by the GC.
The reason is that GC in JS VMs is usually implemented through a Mark-and-Sweep or method that is functionally equivalent. The basic premise is that the GC goes through a cycle that looks like this:
GC marks all objects on the heap as "potentially available for release." This is usually done using the flag switch, which changes the interpretation of existing labels on objects from the value "must be saved" for "safe exit". Thus, at this stage, there is no real iteration over the objects. Telling GC not to “mark” certain objects will actually require additional operations, not less.
The GC starts with the roots of the GC and goes through the link tree, changing the sign of the objects from "safe until release" to "need to save." This is the Mark phase. GC roots can be global objects, the current executable stack, waiting for callbacks in the event loop, etc. The tree trip itself can be done in different ways, with DFS being the easiest.
The GC passes all objects on the heap and deletes everything that is still marked as release safe. This is the Sweep phase. There are many optimizations in this phase, which allows the GC to free the memory used by a group of objects in a single operation. However, this requires at least some level of iteration over groups of objects, if not over the objects themselves.
Now the problem is with the non-GC arena setup: suppose the object in your non-GC arena was supposed to refer to a regular object. During the Mark phase, if this item is not checked, it will be released. This means that all your “non-collectable” objects must be GC-roots in order to “hold” the regular objects to which they belong. And, being a GC root, it has no advantages over direct reference to the GC root. Both must be equally involved in the Mark phase.
The only alternative for your non-collectible item is to not be able to fully reference collectibles. This can be achieved using your own binary heap, rather than using your own JS objects. Binary data will not be interpreted as links, and a heap object will complete its marking phase in one operation. This is what asm.js does: It predetermines a large array that will act as an internal heap. For a VM, the entire array is considered one large object, and therefore no garbage collection is performed on any data structures that are encoded inside it. Using this method has the disadvantage that you must encode all of your objects and data structures in binary heap format and decode them when you want to use them. When working with asm.js, this is handled by the compiler.
source share