List Allocation and Garbage Collection

Slides:



Advertisements
Similar presentations
For(int i = 1; i
Advertisements

Introduction to Memory Management. 2 General Structure of Run-Time Memory.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
(Chapter 5) Deleting Objects
Chapter 6 Data Types
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Chris Riesbeck, Fall 2007 Dynamic Memory Allocation Today Dynamic memory allocation – mechanisms & policies Memory bugs.
Garbage Collection Introduction What is garbage and how can we deal with it? Garbage collection schemes Reference Counting Mark and Sweep Stop and Copy.
ICS220 – Data Structures and Algorithms Lecture 13 Dr. Ken Cosh.
PZ10B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10B - Garbage collection Programming Language Design.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
Lecture 21 Dynamic Memory Allocation:- *Allocation of objects in program ’ s heap _e.g. C ’ s malloc/free or Pascal ’ s new/dispose _e.g. C ’ s malloc/free.
CS-1030 Dr. Mark L. Hornick 1 Pointers And Dynamic Memory.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
CSC321: Programming Languages 11-1 Programming Languages Tucker and Noonan Chapter 11: Memory Management 11.1 The Heap 11.2 Implementation of Dynamic Arrays.
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
Memory Management. History Run-time management of dynamic memory is a necessary activity for modern programming languages Lisp of the 1960’s was one of.
Memory Management Professor Yihjia Tsai Tamkang University.
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
MOSTLY PARALLEL GARBAGE COLLECTION Authors : Hans J. Boehm Alan J. Demers Scott Shenker XEROX PARC Presented by:REVITAL SHABTAI.
CS61C Review Midterm Spring Five Elements of a Computer Control Datapath Memory Input Output.
Reference Types. 2 Objectives Introduce reference types –class –array Discuss details of use –declaration –allocation –assignment –null –parameter –aggregation.
Reference Counters Associate a counter with each heap item Whenever a heap item is created, such as by a new or malloc instruction, initialize the counter.
1 Overview Assignment 6: hints  Living with a garbage collector Assignment 5: solution  Garbage collection.
Garbage Collection. Terminology Heap – a finite pool of data cells, can be organized in many ways Roots - Pointers from the program into the Heap. – We.
Chapter 7 Objects and Memory. Structure of memory The fundamental unit of memory is called a bit, either 0 or 1. In most modern architectures, the smallest.
Simulated Pointers Limitations Of Java Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
Pointers in C++. 7a-2 Pointers "pointer" is a basic type like int or double value of a pointer variable contains the location, or address in memory, of.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
1 Languages and Compilers (SProg og Oversættere) Heap allocation and Garbage Collection.
Heap storage & Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001.
Objects and Variables Local variables – Confined to single context: allocated on stack – Primitive types such as int or object references – Must be initialized.
Memory Management in Java Computer Science 3 Gerb Objective: Understand references to composite types in Java.
Spring, 2011 –– Computational Thinking – Dennis Kafura – CS 2984 Data Structures Mapping complex structures to linear memory.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
Smart Pointers. Dumb Pointers Pointers Necessary – Dynamic memory – Sharing memory.
Memory Management in Java Mr. Gerb Computer Science 4.
Memory Management CSCI 2720 Spring What is memory management? “the prudent utilization of this scarce resource (memory), whether by conservation,
1 Programming Languages (CS 550) List Processing, Dynamic Memory Allocation and Garbage Collection Jeremy R. Johnson.
Data Types Chapter 6: Data Types Lectures # 13. Topics Chapter 6: Data Types 2 Introduction Primitive Data Types Character String Types Array Types Associative.
CSC 533: Programming Languages Spring 2016
Garbage Collection What is garbage and how can we deal with it?
CS345 – Event-driven Programming
Core Java Garbage Collection LEVEL – PRACTITIONER.
CSC 533: Programming Languages Spring 2015
Dynamic Memory Allocation
Concepts of programming languages
Object References James Brucker.
Simulated Pointers.
مدیریت استراتژيک منابع انسانی
Smart Pointers.
Lecture 11 Memory Richard Gesick.
Simulated Pointers.
Strategies for automatic memory management
List Processing in Real Time on a Serial Computer
Data Structures and Algorithms
Ռազմավարական կառավարում
Dynamic Memory.
Heap storage & Garbage collection
List Allocation and Garbage Collection
C H A P T E R F I V E Memory Management.
Data Structures and Algorithms
Heap storage & Garbage collection
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
How Memory Leaks Work with Memory Diagram
Automating Memory Management
CSC 533: Programming Languages Spring 2019
Garbage Collection What is garbage and how can we deal with it?
Presentation transcript:

List Allocation and Garbage Collection Example

Memory Allocation AVAIL = 0  (0 0 0 0 0 0 0 0) Initialize Heap 1 AVAIL = 0  (0 0 0 0 0 0 0 0) Initialize Heap denotes list 2 1 3 2 4 3 5 4 6 5 7 6 -1 7

Memory Allocation AVAIL = 0 (define L (list 1 2 3))  1 AVAIL = 0 (define L (list 1 2 3))  (cons 1 (cons 2 (cons 3 ‘()))) 2 1 3 2 4 3 5 4 6 5 7 6 -1 7

Memory Allocation AVAIL = 1 (define L (list 1 2 3))  -1 AVAIL = 1 (define L (list 1 2 3))  (cons 1 (cons 2 (cons 3 ‘()))) 2 1 3 2 4 3 5 4 6 5 7 6 -1 7

Memory Allocation AVAIL = 2 (define L (list 1 2 3))  -1 AVAIL = 2 (define L (list 1 2 3))  (cons 1 (cons 2 (cons 3 ‘()))) 2 1 3 2 4 3 5 4 6 5 7 6 -1 7

Memory Allocation AVAIL = 3  (0 0 0 0 0) L = 2  (1 2 3) -1 AVAIL = 3  (0 0 0 0 0) L = 2  (1 2 3) (define L (list 1 2 3))  (cons 1 (cons 2 (cons 3 ‘()))) 2 1 1 1 2 4 3 5 4 6 5 7 6 -1 7

Memory Allocation AVAIL = 5  (0 0 0), L = 2  (1 2 3), M = 4  (4 5) -1 AVAIL = 5  (0 0 0), L = 2  (1 2 3), M = 4  (4 5) (define L (list 1 2 3)) (define M (list 4 5)) 2 1 1 1 2 5 -1 3 4 3 4 6 5 7 6 -1 7

Memory Allocation AVAIL = -1  NULL, L = 2  (1 2 3), M = 4  (4 5) AVAIL = -1  NULL, L = 2  (1 2 3), M = 4  (4 5) N = 7  (6 7 8) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) 2 1 1 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Memory Allocation AVAIL = -1  NULL, L = 2  ((4 5) 2 3), AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 4  (4 5) N = 7  (6 7 8) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M); overlap 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Memory Allocation AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 7  (6 7 8) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) ; cells still accessible 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Memory Allocation AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) ; cells garbage 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Garbage Collection AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)); AVAIL = NULL  garbage collection 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Mark AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Mark AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Mark AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Mark AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Mark AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] AVAIL = -1  NULL, L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Mark L 2 1 4 1 2 5 -1 3 4 3 4 8 -1 5 7 5 6 6 6 7

Sweep AVAIL = 5  (0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] -1 AVAIL = 5  (0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Reclaim unmarked cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 7 5 6 6 6 7

Sweep AVAIL = 6  (0 0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] -1 AVAIL = 6  (0 0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Reclaim unmarked cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 6 6 7

Sweep AVAIL = 7  (0 0 0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] -1 AVAIL = 7  (0 0 0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Reclaim unmarked cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 6 7

Sweep AVAIL = 7  (0 0 0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] -1 AVAIL = 7  (0 0 0) L = 2  ((4 5) 2 3), M = 0 [int] N = 0 [int] (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) Unmark cells 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 6 7

Memory Allocation AVAIL = 6  (0 0) L = 2  ((4 5) 2 3), M = 0 [int] -1 AVAIL = 6  (0 0) L = 2  ((4 5) 2 3), M = 0 [int] N = 7  (1) (define L (list 1 2 3)) (define M (list 4 5)) (define N (list 6 7 8)) (set-car! L M) (define M 0) (define N 0) (define N (list 1)) 2 1 4 1 2 5 -1 3 4 3 4 -1 5 5 6 1 -1 7