File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
part9 (Advanced Topics)/Memory-Managment Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ INFO: What is Memory Lifecycle in JavaScript ?
3+ JavaScript, like most high-level languages, handles memory automatically.
4+
5+ Memory lifecycle has 3 phases:
6+ 1. Allocation: memory is reserved when variables or functions are declared.
7+ 2. Usage: you work with that memory (access/change variables, call functions).
8+ 3. Release (Garbage Collection): JS automatically frees memory that's no longer used.
9+ */
10+
11+ // Exmaple
12+ function greet ( ) {
13+ const name = "Rafay" ; // Allocation
14+ console . log ( "Hello" , name ) ; // Usage
15+ } // when function ends, memory for `name` is released
16+
17+ /*
18+ INFO: What is Garbage Collection ?
19+ Garbage Collection is the process of automatically freeing memory that's no longer reachalbe/used in the program.
20+ JavaScript uses a garbage collector to scan memory and clean up values that can't be reached anymore.
21+ */
You can’t perform that action at this time.
0 commit comments