#How can I debug the memory usage of my code?

1 messages · Page 1 of 1 (latest)

zenith cloud
#

I have a program that seems to have a memory leak, but I'm not sure how to debug it

#

I'm running my program in a docker container in production. I would like to debug memory usage in prod.

restive crag
#

require(“bun:jsc”).heapStats() will give you an object with a bunch of data about what’s in the heap

#

You can also use the —smol flag to use a smaller heap

#

You can use process.memoryUsage() to get the current memory usage

zenith cloud
#

apart from the object type count which can lead me in the right direction

restive crag
#

You can use bun —inspect and then get a heap profile

#

And then it will show you a graph of why various objects exist in memory

zenith cloud
#

i'll try that locally then, as it's pretty janky to do in prod

#

thanks!

restive crag
#

To be clear I think it’s kind of not great right now

#

We really need some kind of monitoring thing

zenith cloud
#

okay looking into this a bit more, it seems to be that intentionally unhandled promises are staying in memory including their context. seems like a bun issue as i can't reproduce with the exact same code in node

restive crag
#

If you call .then on them

#

But leave the catch callback

#

Does it change anything