1 of 10

CSE 163

Memory Management

Hunter Schafer

2 of 10

Memory

2

3 of 10

Memory

Just a big array/list to store values

  • Names of these regions are not important for us

3

4 of 10

Objects

  • Data and objects are just chunks of memory
  • When you construct an object, the computer gives you an appropriately sized chunk of memory
    • The fields are just specific locations within a chunk to store data�
  • This is why we need the difference between equality of value and equality of identity
    • Equal value: memory chunks store the same values
    • Equal identity: same chunk of memory�
  • By creating objects, you are making your program use more memory

4

5 of 10

Creating Objects

VS Code

  • Every time an object is created, it takes up a bit of memory
  • This can build up over time
  • If an object is not referenced, it will get garbage collected.

  • Natural question, who would ever create this many objects?
    • You did on HW4!

Using pickle to store object in a file

5

6 of 10

Memory Hierarchy

  • The memory we have been talking about is volatile memory
    • If you shut your computer down, it all disappears
  • It’s great because it’s relatively fast and can store a moderate amount of data (~16GB)
  • However it’s not the fastest nor can it store the most data

6

7 of 10

Memory Hierarchy

7

8 of 10

Disk Drive

8

9 of 10

Paging

  • When working with big data, it might be the case that your data doesn’t fit in memory
  • In this case, your computer will send big chunks of memory to disk until it’s needed later
  • This can cause huge slow downs in your program since reading/writing to disk is generally slow

9

10 of 10

General Takeaways

  • Don’t store references to data you don’t need
    • Restrict global variables
  • Keep things local
    • Don’t iterate through data in random order
  • When developing, use a small random sample of your data so you don’t have to work with the whole thing.

10