r/javascript • • Sep 12 '22

Facebook Open Sources MemLab: A framework for finding JavaScript memory leaks

https://engineering.fb.com/2022/09/12/open-source/memlab/
370 Upvotes

18 comments sorted by

8

u/magicalDon Sep 13 '22

This one looks amazing!

8

u/thruster_fuel69 Sep 13 '22

Yes it's a great advertisement for React! /s

12

u/[deleted] Sep 13 '22

I guess they needed a tool to fix jest

6

u/binhonglee Sep 13 '22

Jest has been owned by Open JS Foundation for a while now.

https://openjsf.org/blog/2022/05/11/openjs-foundation-welcomes-jest/

2

u/discourseur Sep 13 '22

Did dev pick up steam? Jest is abandonware…

1

u/chrisddie61527 Sep 14 '22

what's the alternative?

9

u/mungaihaha Sep 13 '22 edited Sep 13 '22

How does a garbage collected language like JS leak memory?

EDIT: Makes a lot more sense now. Thank you all for the answers

33

u/rk06 Sep 13 '22

Memory Leak in garbage collected world refers to objects which remain accessible (and therefore can't be garbage collected) despite outliving their purpose.

17

u/justrhysism Sep 13 '22

People not cleaning up after themselves properly.

11

u/ShortFuse Sep 13 '22
this.element = document.createElement('div');
// Some time later
this.element.remove();

this.element leaks. Same applies with element references in timers and promises. We have WeakRef now, but I don't think many outside of vanilla JS devs use them.

MDN's reference for WeakRef has an example of how a timer paradigm that usually leaks no longer would with WeakRef.

1

u/cypther_py Sep 17 '22

This seems dope

0

u/[deleted] Sep 13 '22

[deleted]

56

u/YodaCodar Sep 13 '22

They needed the tool so they built it. It doesnt mean theyve used it yet…

34

u/MaxUumen Sep 13 '22

They open sourced it so the community can find and fix memory leaks in it. Oh wait...

0

u/[deleted] Sep 13 '22

[deleted]

1

u/[deleted] Sep 13 '22

Because it's built on php and because the main structure from the original FB site is still there, they've been simply adding stuff for 15 years

0

u/[deleted] Sep 13 '22

[deleted]

2

u/_RollForInitiative_ Sep 13 '22

It's fairly ancient react.

1

u/visualdescript Sep 14 '22

The most ancient of all!