Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS 内存回收机制 #577

Open
cisen opened this issue Jul 24, 2019 · 0 comments
Open

JS 内存回收机制 #577

cisen opened this issue Jul 24, 2019 · 0 comments

Comments

@cisen
Copy link
Owner

cisen commented Jul 24, 2019

总结

说明

  • 是所有对象都有type_flags_refs记录被引用的次数
  • 全局context会有一个ecma_gc_objects_p单向链表,所有被创建的对象都会登记到链表中,链表的连接通过gc_next_cp指针连接到一起
  • 垃圾回收的方法就是遍历这个链表,看哪个type_flags_refs数量为0就回收它,这么简单

会触发gc的情况

  • 手动,对外有两个api,一个是jerry_gc单纯gc,一个jerry_cleanup所有内存回收
  • 每次使用jmem_heap_gc_and_alloc_block函数分配内存的时候,都会判断所需内存是否超出限制,如果超出限制则会执行jmem_free_unused_memory_callback调用ecma_gc_run遍历ecma_gc_objects_p链表来回收内存。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant