JS:简介什么对象构造器是垃圾收集

时间:2022-04-13 23:54:52

Is there a way to know what type of objects are being garbage-collected the most in a Javascript application?

有没有办法知道在Javascript应用程序中哪些类型的对象被垃圾收集最多?

I do know I can get Heap Snapshot but that only tells what objects are the most common, not the most garbage-collected.

我知道我可以获得堆快照但只能告诉哪些对象是最常见的,而不是最垃圾收集的。

And Heap Allocations do not give detailed information about Object class.

并且堆分配不提供有关Object类的详细信息。

2 个解决方案

#1


1  

Using which JavaScript runtime engine? Each engine will have its own GC and its own way of monitoring GC events. The Chrome V8 engine would be a good place to start if you are trying to learn more about one GC implementation: https://developers.google.com/v8/ If you pull in the source from github https://chromium.googlesource.com/v8/v8.git you will find files src/heap/gc-tracer.[h|cc] provide a lot of capability, and you could add more for your own profiling needs.

使用哪个JavaScript运行时引擎?每个引擎都有自己的GC和自己监控GC事件的方式。如果您想了解有关GC实施的更多信息,Chrome V8引擎将是一个很好的起点:https://developers.google.com/v8/如果您从github https://chromium.googlesource获取来源.com / v8 / v8.git你会发现文件src / heap / gc-tracer。[h | cc]提供了很多功能,你可以为自己的分析需求添加更多功能。

#2


1  

I guess you can do this by taking multiple heap snapshots and then comparing the snapshots to identify which objects are being grabage collected. You can refer to this answer. Hope it helps :)

我想你可以通过获取多个堆快照然后比较快照来识别哪些对象是垃圾收集来实现这一点。你可以参考这个答案。希望能帮助到你 :)

#1


1  

Using which JavaScript runtime engine? Each engine will have its own GC and its own way of monitoring GC events. The Chrome V8 engine would be a good place to start if you are trying to learn more about one GC implementation: https://developers.google.com/v8/ If you pull in the source from github https://chromium.googlesource.com/v8/v8.git you will find files src/heap/gc-tracer.[h|cc] provide a lot of capability, and you could add more for your own profiling needs.

使用哪个JavaScript运行时引擎?每个引擎都有自己的GC和自己监控GC事件的方式。如果您想了解有关GC实施的更多信息,Chrome V8引擎将是一个很好的起点:https://developers.google.com/v8/如果您从github https://chromium.googlesource获取来源.com / v8 / v8.git你会发现文件src / heap / gc-tracer。[h | cc]提供了很多功能,你可以为自己的分析需求添加更多功能。

#2


1  

I guess you can do this by taking multiple heap snapshots and then comparing the snapshots to identify which objects are being grabage collected. You can refer to this answer. Hope it helps :)

我想你可以通过获取多个堆快照然后比较快照来识别哪些对象是垃圾收集来实现这一点。你可以参考这个答案。希望能帮助到你 :)