# Qs: Memory

***

## How many bits in 1 byte?

8 bits

***

## Which statements about garbage collection and memory leaks are true?

1. Garbage collection automatically frees all unused memory.
2. Memory leaks can still occur even in garbage-collected languages.
3. Circular references can prevent garbage collectors from reclaiming memory.
4. Garbage collectors operate in real-time, immediately reclaiming memory when it's no longer referenced.

2 and 3

***

## Which type of memory is generally preferred for storing temporary data in a program, such as local variables within a function?

Stack

***

## Garbage collection and memory leaks

Memory leaks can still occur even in garbage-collected languages.

Circular references can prevent garbage collectors from reclaiming memory.

Garbage collection does NOT:

* automatically free memory
* operate in real-time by immediately reclaiming memory when no longer referenced

***

## In the memory hierarchy, which type of memory typically has the fastest access time?

Fastest to slowest:

a. SSD

b. CPU Cache (L1, L2, L3)

c. HDD

d. RAM

Solution:

1. CPU Cache (L1, L2, L3) - the fastest and most expensive memory type.
2. RAM
3. SSD
4. HDD

***

## Steps a CPU follows to interpret code in a CPU Cycle?

* Fetch
* Decode
* Execute

***

## In a computer system using 32-bit addressing, how much total memory can be addressed?

2^32 bytes

***

## Rank from fastest to slowest ?

a. Reading 1MB from SSD

b. Decompressing 1MB with a simple compression algorithm

c. Reading 1MB from RAM

d. Reading 1MB from HDD

e. Downloading 1MB over the network

Solution:

1. Reading 1MB from RAM
2. Decompressing 1MB with a simple compression algorithm (e.g., LZ4)
3. Reading 1MB from SSD
4. Reading 1MB from HDD
5. Downloading 1MB over the network
