0

I have a lot of a long live objects in memory(~10GB) and I definitely know that these objects never be collected by GC. The problem is that a mark-sweep gc action take a long time(90sec) to check all objects in memory and its relations. I need some way to skip my objects from collecting.

I've tried to use Persistent::MarkIndependent, but it doesn't work for me.

cevek
  • 862
  • 1
  • 7
  • 16

1 Answers1

3

If the objects in question are references held live via handles from C++ than they will not be collected. However, the collector still has to traverse them, because it has to find all references to other objects that they contain. If it didn't do that then you would potentially get dangling pointers and make the VM crash.

So, no, at least the way you describe it, that can't be done. (If, on the other hand, these objects cannot contain random pointers because e.g. they are array buffers or strings then the GC knows that it doesn't need to traverse them so there shouldn't be a performance issue.)

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72
  • Thank you for detailed explanation, but I still don't understand what could be happen if I skip my objects and its relations from traversing, how these dangling pointers make the VM crash? Is it could be happen when the gc moves my object from one memory page to another or what? – cevek Jan 14 '18 at 19:15
  • 1
    Every object not visited by the GC's marking phase is considered dead and collected. If it doesn't traverse your large object it might hence collect some of the other objects that one is referencing and collect them. Then your object has dangling references. – Andreas Rossberg Jan 15 '18 at 07:56
  • Ok, last question, if I mark all my objects and its references(objects, strings, buffers) as dead and collected, nothing bad can happen right? – cevek Jan 15 '18 at 11:21
  • Not sure what you mean. You cannot mark anything dead. And the GC only marks things live. Everything it doesn't get to see is considered dead and the memory reused. – Andreas Rossberg Jan 15 '18 at 13:40
  • I'm curious about a condition in the GC traverser(mark sweep) that decides to enter to a graph object or not when it iterates all root objects. I want mark all my selected objects and full graph of objects that it referenced with skipping flag(always live - white?) and when the GC is performing never to enter to this marked objects. – cevek Jan 15 '18 at 14:04
  • There is no access to the GC's internal marking flags, and intentionally so. All flags are reinitialised for each GC anyway, so there is no way avoiding traversing them again. This is fundamental to how GC works. – Andreas Rossberg Jan 16 '18 at 12:03