Skip to content

Commit 062a8a0

Browse files
feat: add memory managment
1 parent c514225 commit 062a8a0

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
*/

0 commit comments

Comments
 (0)