From 9cb8dcf74c15318cc9bed8732595f7d438d6579c Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 21:35:32 -0600 Subject: [PATCH 01/10] =?UTF-8?q?"any=20more"=20=E2=86=92=20"anymore"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index 1b576d6293..8dabe1cb2a 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -2,7 +2,7 @@ Memory management in JavaScript is performed automatically and invisibly to us. We create primitives, objects, functions... All that takes memory. -What happens when something is not needed any more? How does the JavaScript engine discover it and clean it up? +What happens when something is not needed anymore? How does the JavaScript engine discover it and clean it up? ## Reachability From e26b617422518d334f2b07f55967ed8279127caa Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 21:43:07 -0600 Subject: [PATCH 02/10] Add missing "the" --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index 8dabe1cb2a..4952f22650 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -25,7 +25,7 @@ Simply put, "reachable" values are those that are accessible or usable somehow. For instance, if there's an object in a global variable, and that object has a property referencing another object, *that* object is considered reachable. And those that it references are also reachable. Detailed examples to follow. -There's a background process in the JavaScript engine that is called [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that have become unreachable. +There's a background process in the JavaScript engine that is called the [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that have become unreachable. ## A simple example From 9d12b1a434a4a29bab4b6b95a729730938a1487d Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 21:44:57 -0600 Subject: [PATCH 03/10] Add missing comma --- 1-js/04-object-basics/03-garbage-collection/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index 4952f22650..bdfb697f2c 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -25,7 +25,7 @@ Simply put, "reachable" values are those that are accessible or usable somehow. For instance, if there's an object in a global variable, and that object has a property referencing another object, *that* object is considered reachable. And those that it references are also reachable. Detailed examples to follow. -There's a background process in the JavaScript engine that is called the [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that have become unreachable. +There's a background process in the JavaScript engine called the [garbage collector](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)). It monitors all objects and removes those that have become unreachable. ## A simple example @@ -40,7 +40,7 @@ let user = { ![](memory-user-john.svg) -Here the arrow depicts an object reference. The global variable `"user"` references the object `{name: "John"}` (we'll call it John for brevity). The `"name"` property of John stores a primitive, so it's painted inside the object. +Here, the arrow depicts an object reference. The global variable `"user"` references the object `{name: "John"}` (we'll call it John for brevity). The `"name"` property of John stores a primitive, so it's painted inside the object. If the value of `user` is overwritten, the reference is lost: From 32e6fca97f28fb6ccf719b8c5fdd5f0d0250c170 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 21:46:43 -0600 Subject: [PATCH 04/10] Remove unnecessary quotes --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index bdfb697f2c..1e040c39af 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -40,7 +40,7 @@ let user = { ![](memory-user-john.svg) -Here, the arrow depicts an object reference. The global variable `"user"` references the object `{name: "John"}` (we'll call it John for brevity). The `"name"` property of John stores a primitive, so it's painted inside the object. +Here, the arrow depicts an object reference. The global variable `user` references the object `{name: "John"}` (we'll call it John for brevity). The `name` property of John stores a primitive, so it's painted inside the object. If the value of `user` is overwritten, the reference is lost: From 52d9c699aa4b52ba9073581dc1a5f8453f470eb3 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 21:48:52 -0600 Subject: [PATCH 05/10] Clarify diagram explanation Previously, it said "painted", which seems less clear than "shown". --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index 1e040c39af..b6fc241ff1 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -40,7 +40,7 @@ let user = { ![](memory-user-john.svg) -Here, the arrow depicts an object reference. The global variable `user` references the object `{name: "John"}` (we'll call it John for brevity). The `name` property of John stores a primitive, so it's painted inside the object. +Here, the arrow depicts an object reference. The global variable `user` references the object `{name: "John"}` (we'll call it John for brevity). The `name` property of John stores a primitive, so it's shown inside the object. If the value of `user` is overwritten, the reference is lost: From 534bc0fcbf248c954415f473159b30ce36fc2b13 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 21:50:29 -0600 Subject: [PATCH 06/10] Add another missing "the" --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index b6fc241ff1..fc892d1464 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -74,7 +74,7 @@ Now if we do the same: user = null; ``` -...Then the object is still reachable via `admin` global variable, so it must stay in memory. If we overwrite `admin` too, then it can be removed. +...Then the object is still reachable via the `admin` global variable, so it must stay in memory. If we overwrite `admin` too, then it can be removed. ## Interlinked objects From ab1203f24cd73a09948aabfb38ddf43a97104d8f Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 21:53:52 -0600 Subject: [PATCH 07/10] =?UTF-8?q?Another=20"any=20more"=20=20=E2=86=92=20"?= =?UTF-8?q?anymore"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index fc892d1464..4be4fef80f 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -117,7 +117,7 @@ delete family.mother.husband; It's not enough to delete only one of these two references, because all objects would still be reachable. -But if we delete both, then we can see that John has no incoming reference any more: +But if we delete both, then we can see that John has no incoming reference anymore: ![](family-no-father.svg) From 32eda46ceb61912f81582cca1237966d9ea66859 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 22:05:26 -0600 Subject: [PATCH 08/10] Use colons instead of dashes Though em dashes are great, they're not always the tool for the job. --- 1-js/04-object-basics/03-garbage-collection/article.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index 4be4fef80f..aa7b0504c4 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -187,9 +187,9 @@ That's the concept of how garbage collection works. JavaScript engines apply man Some of the optimizations: -- **Generational collection** -- objects are split into two sets: "new ones" and "old ones". In typical code, many objects have a short life span: they appear, do their job and die fast, so it makes sense to track new objects and clear the memory from them if that's the case. Those that survive for long enough, become "old" and are examined less often. -- **Incremental collection** -- if there are many objects, and we try to walk and mark the whole object set at once, it may take some time and introduce visible delays in the execution. So the engine splits the whole set of existing objects into multiple parts. And then clear these parts one after another. There are many small garbage collections instead of a total one. That requires some extra bookkeeping between them to track changes, but we get many tiny delays instead of a big one. -- **Idle-time collection** -- the garbage collector tries to run only while the CPU is idle, to reduce the possible effect on the execution. +- **Generational collection**: objects are split into two sets: "new ones" and "old ones". In typical code, many objects have a short life span: they appear, do their job and die fast, so it makes sense to track new objects and clear the memory from them if that's the case. Those that survive for long enough, become "old" and are examined less often. +- **Incremental collection**: if there are many objects, and we try to walk and mark the whole object set at once, it may take some time and introduce visible delays in the execution. So the engine splits the whole set of existing objects into multiple parts. And then clear these parts one after another. There are many small garbage collections instead of a total one. That requires some extra bookkeeping between them to track changes, but we get many tiny delays instead of a big one. +- **Idle-time collection**: the garbage collector tries to run only while the CPU is idle, to reduce the possible effect on the execution. There exist other optimizations and flavours of garbage collection algorithms. As much as I'd like to describe them here, I have to hold off, because different engines implement different tweaks and techniques. And, what's even more important, things change as engines develop, so studying deeper "in advance", without a real need is probably not worth that. Unless, of course, it is a matter of pure interest, then there will be some links for you below. From 52fb541e3c8c42dd5309c4a9d3f0b19aa9e6b780 Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 22:06:59 -0600 Subject: [PATCH 09/10] Add missing 's' --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index aa7b0504c4..fa875430cb 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -188,7 +188,7 @@ That's the concept of how garbage collection works. JavaScript engines apply man Some of the optimizations: - **Generational collection**: objects are split into two sets: "new ones" and "old ones". In typical code, many objects have a short life span: they appear, do their job and die fast, so it makes sense to track new objects and clear the memory from them if that's the case. Those that survive for long enough, become "old" and are examined less often. -- **Incremental collection**: if there are many objects, and we try to walk and mark the whole object set at once, it may take some time and introduce visible delays in the execution. So the engine splits the whole set of existing objects into multiple parts. And then clear these parts one after another. There are many small garbage collections instead of a total one. That requires some extra bookkeeping between them to track changes, but we get many tiny delays instead of a big one. +- **Incremental collection**: if there are many objects, and we try to walk and mark the whole object set at once, it may take some time and introduce visible delays in the execution. So the engine splits the whole set of existing objects into multiple parts. And then clears these parts one after another. There are many small garbage collections instead of a total one. That requires some extra bookkeeping between them to track changes, but we get many tiny delays instead of a big one. - **Idle-time collection**: the garbage collector tries to run only while the CPU is idle, to reduce the possible effect on the execution. There exist other optimizations and flavours of garbage collection algorithms. As much as I'd like to describe them here, I have to hold off, because different engines implement different tweaks and techniques. And, what's even more important, things change as engines develop, so studying deeper "in advance", without a real need is probably not worth that. Unless, of course, it is a matter of pure interest, then there will be some links for you below. From b89c9340402ac6150837f5326849e905cf3865da Mon Sep 17 00:00:00 2001 From: Bradley Turek Date: 2024年7月20日 22:10:47 -0600 Subject: [PATCH 10/10] Remove some unnecessary punctuation --- 1-js/04-object-basics/03-garbage-collection/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/04-object-basics/03-garbage-collection/article.md b/1-js/04-object-basics/03-garbage-collection/article.md index fa875430cb..5ad71b91f4 100644 --- a/1-js/04-object-basics/03-garbage-collection/article.md +++ b/1-js/04-object-basics/03-garbage-collection/article.md @@ -207,6 +207,6 @@ A general book "The Garbage Collection Handbook: The Art of Automatic Memory Man If you are familiar with low-level programming, more detailed information about V8's garbage collector is in the article [A tour of V8: Garbage Collection](https://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection). -The [V8 blog](https://v8.dev/) also publishes articles about changes in memory management from time to time. Naturally, to learn more about garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](https://mrale.ph) who worked as one of the V8 engineers. I'm saying: "V8", because it is best covered by articles on the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects. +The [V8 blog](https://v8.dev/) also publishes articles about changes in memory management from time to time. Naturally, to learn more about garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](https://mrale.ph) who worked as one of the V8 engineers. I'm saying "V8" because it is best covered by articles on the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects. In-depth knowledge of engines is good when you need low-level optimizations. It would be wise to plan that as the next step after you're familiar with the language.

AltStyle によって変換されたページ (->オリジナル) /