forked from lurkingryuu/KOSS_teaching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatter.txt
37 lines (34 loc) · 2.46 KB
/
Matter.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
1. Garbage Collection
---------------------------------------------------------------------------------------------------------------------------------
Garbage Collection is a form of Automatic Memory Mangement, which tries to reclaim memory which was allocated by the program, but is no longer referenced.
Pros:
- No need to Manually deallocate memory.(programmer errors(Dangling pointers, Double free, memory leaks), skill threshold)
Cons:
- Additional Computational time and resources and is overhead.
- Less control in hands of programmers sometimes...
- The moment of garbage collection(lags, hangs in applications)
---------------------------------------------------------------------------------------------------------------------------------
2. Garbage Collection Strategies
---------------------------------------------------------------------------------------------------------------------------------
# Mark-sweep algorithm
- It is one of the Garbage collection techniques used by Garbage collectors in Java and is used as a major garbage collector in javascript.
- Algorithm
- When an object is initialized, it's in an unmarked state.
- In Marking Phase, we mark all of the objects which are reachable.
- We parse through all objects, if an object is marked, we unmark it, else we free the memory used by that object
- We Repeat this process of marking and sweeping
# Reference counting
- It is used in Python
- Algorithm
- When an object is created and stored in a variable, it is given a value of 1.
- The value denotes the number of direct references to an object.
- If an objects value reaches 0, it is called a dead object and the space used by that object is reclaimed.
---------------------------------------------------------------------------------------------------------------------------------
3. Ownership model in Rust
---------------------------------------------------------------------------------------------------------------------------------
Memory management can be done in ways other than Garbage collection or Manual memory management, like the Ownership model used in Rust.
In this Model, there are some rules to be followed while programming, if not followed, will give compile time errors.
# Ownership Rules
- Each value in Rust has a variable That's called it's owner.
- There can only be one owner at a time.
- When the owner goes out of scope the value will be dropped.