-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Integration
In the implementation of our custom JS Objects used with mozjs, we store data/objects associated with our JS Objects inside the private slot data region of the JS Objects. The data stored in the private slot dataregion is not tracked by the mozjs garbage collector, since it is stored as a void* and typically has not been allocated through the spidermonkey/cell allocation code.
This is usually benign, but for cases where we have large objects in the underlying private slot data, it means that we consume more memory than the GC is aware of, and leads to the GC not being called as it should. One such example is BSONInfo. BSONInfo stores a BSONObj that was not allocated by mozjs, but could consume a significant amount of memory that is not being tracked by the GC.
To overcome this, incorporate the use of AddAssociatedMemory/RemoveAssociatedMemory (see https://searchfox.org/mozilla-central/source/js/public/MemoryFunctions.h#72-86) to inform the GC of the additional memory usage associated with the JS Object.