Open dpbeaumont opened 10 months ago
Hey @dpbeaumont! You're absolutely right, there is a memory leak in Lucid. In fact, there are several. I left a brief explanation in the pull request I opened (#232) to fix this specific issue, and I will continue to open PRs to incrementally resolve memory management issues throughout the library whenever I can.
This is already fixed in the CML develop branch, so it will go away once Lucid updates to the latest CML version
I've been doing some testing and I have noticed memory usage proportionally increasing when Lucid is consumed in a long running application. Over time this memory usage compounds, and eventually uses a machines full memory allowance, causing various memory exceptions from here on.
This occurs when used in the context of long running application, or one with looping. I can see memory marked as external consistently increases and does not get garbage collected. I have tested using various looping approaches, while loops, for loops, interval loops & async loops in an attempt to try and force this external resource cleanup.
Replication steps are using the
Data.from()
method to showcase this. I can see the following: -External memory constantly increasing in each loop. mainly proportionally, until application end. -Heap used, increasing/decreasing (stable as expected). -Rss constantly increasing. -Array buffers increasing/decreasing (stable as expected).When we reach the 100k loop, you can see the external memory in use is 209.05mb which is significant.
![image](https://github.com/spacebudz/lucid/assets/49551821/8418f06b-2abf-49c5-960a-e1770d2ca18a)
StackBlitz here demonstrates the code I used to test this and shows minimal replication steps, in a nodejs application: https://stackblitz.com/edit/node-wdg1xb?file=index.js
Heap performance profile of operation:![image](https://github.com/spacebudz/lucid/assets/49551821/218a672e-c6cd-4493-aa50-0fa821895617)