News for hackers. Stuff that matters.
Re:How to detect if an object has been garbage collected in ... by neetodavid on Tuesday May 26, 2020 @03:16PM (#23315294)
Being able to automate tests for memory leaks is very helpful but I would much rather incorporate the browser dev tools than not when debugging memory. Doing it only in javascript feels very janky (weak maps, attaching giant array objects to things, waiting ?? amount of time for the automated GC to run).

I was debugging memory leaks in some pretty large javascript products and while I did initially start with methods like this post, I only started to make reliable progress when I became familiar with the heap snapshot tool. Diagnosing problem is trivial (just filter the heap snapshot by a Class name and count the instances) and it is The Tool To Use to actually resolve it (tracing the chain of references in the retainers view)

In the future if I need to write automated tests to identify memory leaks I will look into automating the Dev Tools rather than fumbling with WeakMap or performance.memory.usedJSHeapSize

Re:How to detect if an object has been garbage collected in ... by hoten on Wednesday May 27, 2020 @01:19AM (#23319615)
I used the chrome devtools protocol to write a memory leak detector for my game. Has helped me quite a bit. If you like I can share the source.
Re:How to detect if an object has been garbage collected in ... by hoten on Wednesday May 27, 2020 @02:58PM (#23328151)
Here it is: https://gist.github.com/connorjclark/549fa524a0b8fdc8bbb1b48...

I left some annotations in a comment. Hope it helps!

Re:How to detect if an object has been garbage collected in ... by gargarplex on Wednesday May 27, 2020 @03:35AM (#23320418)
+1.
Re:How to detect if an object has been garbage collected in ... by hoten on Wednesday May 27, 2020 @02:59PM (#23328156)
Replied to my comment with link.
Re:How to detect if an object has been garbage collected in ... by iaml on Wednesday May 27, 2020 @07:50AM (#23321893)
Would be very useful for me
Re:How to detect if an object has been garbage collected in ... by hoten on Wednesday May 27, 2020 @02:58PM (#23328154)
Replied to my comment with link.
Re:How to detect if an object has been garbage collected in ... by londons_explore on Wednesday May 27, 2020 @01:21AM (#23319622)
The devtools protocol is super simple. It's very easy to automate everything devtools can do. You can do it with something high level like puppeteer/selenium, or just directly with a websocket to the browser.

The API is documented here:. https://chromedevtools.github.io/devtools-protocol/

Re:How to detect if an object has been garbage collected in ... by Sophistifunk on Wednesday May 27, 2020 @07:06PM (#23331258)
It'd be better if the committee would just stop pretending that JS has some sort of holy determinism that would go away if we were allowed weak references. They're going to have to put it in soon anyway in order to support wasm refs.
Re:How to detect if an object has been garbage collected in ... by darepublic on Wednesday May 27, 2020 @10:44PM (#23332836)
I guess I'm a noob but I always stumble when trying to use the chrome dev tool profiling.. I love other aspects of the dev tools but not that