Download presentation
Presentation is loading. Please wait.
Published byLynette Terry Modified over 8 years ago
1
GARBAGE COLLECTION Student: Jack Chang
2
Introduction Manual memory management Memory bugs Automatic memory management We know... A program can only use objects that can be found.
3
Reference Counting Reference Count Store reference count in each object For each assignment operation, update reference count If reference count equals 0, we de-allocate the object. X 1 Object i Y 2 Object j Z Figure 1: Example objects
4
Reference Counting X Y 1 1 Object i Object j X Y 1-1 1+1 Object i Object j Step 0: Start Step 1: Y = Object i;
5
Reference Counting X Y 0 2 Object i Object j X Y 2 Object i Step 3: Check right hand side Step 4: Finish assignment
6
Reference Counting Advantages Easy to implement Does not wait till memory is exhausted Disadvantages...
7
Reference Counting Assignment operation gets slower X 1 1 1 1 1 1 1
8
Reference Counting Assignment operation gets slower X 0 1 1 1 1 1 1
9
Reference Counting Does not work with circular structure X 1 2 Object i Object j
10
Reference Counting Does not work with circular structure X 1 1 Object i Object j
11
Stop and Copy Old SpaceNew Space Allocation Pointer New Space AB CDE Allocation Pointer
12
Stop and Copy New Space AB CDE Root set Allocation Pointer Scan Pointer
13
Stop and Copy AB CDE Root set A Scan Pointer Allocation Pointer AB CDE Root set A Scan Pointer Allocation Pointer B
14
Stop and Copy Old Space New Space ABE Root set
15
Stop and Copy Advantages Defragment memory during garbage collection The more garbage the faster it will be Disadvantages Need to copy all the reachable objects to new space Need twice as much memory as the program actually uses
16
At the end The garbage collection is convenient, but... Pauses There are more advanced garbage collection algorithms Concurrent Parallel Thank you.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.