Closed cmidgley closed 4 weeks ago
Would you believe that this is debugging feature?
The leak does not occur in instrumented or release builds. Here's the output from an instrumented build:
Leak test at 2024-09-01T23:08:31.514Z for 100 iterations
Chunk heap usage: 0
Slot heap usage: 0
What's happening is that XS is making the source text of the evaluate
(or globalThis.eval
) available for debugging. To do that, a dynamic identifier (path name) is created and the source text is transmitted to xsbug which caches it on your computer. XS uses a symbol to hold the path to the source text. The memory use you are seeing is that symbol.
You can disable the transmission of source text on ESP32 by removing these lines. If it would help, we could add a flag to disable that at compile time.
FWIW – in theory that symbol can be garbage collected when the byte code is no longer referenced. XS doesn't do this because it would make garbage collection much slower as it would require scanning byte code to determine symbols in-use.
Thanks for explaining what's going on. It makes sense and no need to add any flag. I'll try release mode when investigating similar issues in the future.
Build environment: Windows Moddable SDK version: 4.9.0-14-g2d3b810d6 Target device: Win (sim) and ESP32
Description
Compartment.evaluate
appears to have a memory leak of 16 bytes on the chunk heap and 12 bytes on the slot heap on each call.Steps to Reproduce
evaluate
In the example repo, I use
Debug.gc()
before eachInstrumentation
collection, which I believe should report fairly accurate numbers. I have found this leak scales linearly with usage, and does not appear to depend on what is executed (empty script and complex scripts both have the same resulting heap usage).