GarbageCollection

GarbageCollection - Implementing functions Expressive Power First-class Functions Programmer’s Productivity Implementation c Copyright 2006

Info iconThis preview shows pages 1–11. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Implementing functions Expressive Power First-class Functions Programmer’s Productivity Implementation c Copyright 2006 Norman Ramsey. All Rights Reserved. 1 Memory Management In the beginning, there was FORTRAN: • no dynamically allocated memory • static arrays with fixed limits • a significant style as recently as 1983 (T E X) • still important for hard real-time systems Dynamic allocation, explicit memory management: • Pascal (new/dispose) • C (malloc/free) • C++ (new/delete) Still an area for some research: • efficiency • locality (important for memory hierarchy) • avoiding fragmentation ... many schemes (Knuth, vol. 1; also Grunwald & Zorn) c Copyright 2006 Norman Ramsey. All Rights Reserved. 2 The terror of free When do you call free ? • must call sometime malloc without free ⇒ “memory leak” • premature call to free ⇒ dangling reference hello, core dump! The things we do... • forget about free, just pray • crufty interfaces — who must call free ? two ways to call every procedure? • return pointers to static memory? Ouch! • make copies of things I own my copy, you own yours We can do better ... c Copyright 2006 Norman Ramsey. All Rights Reserved. 3 Automatic Memory Management Why not have malloc without free ? let memory be freed automatically why not call it cons Can be required in the language definition: No Scheme object is ever destroyed. The reason that implementations of Scheme do not (usually!) run out of storage is that they are permitted to reclaim the storage occupied by an object if they can prove that the object cannot possibly matter to any future computation. Hits mainstream circa 1997 (Java) Plan of study: • see how garbage is created • see how we identify it • discuss ways of reclaiming it c Copyright 2006 Norman Ramsey. All Rights Reserved. 4 Garbage Creation Association list for instructor (set nr ’((Course 152) (Office (Maxwell-Dworkin 231)) (Email [email protected]))) nr 152 Email [email protected] Course Office 231 Maxwell-Dworkin c Copyright 2006 Norman Ramsey. All Rights Reserved. 5 Executions create garbage (define bind (x y alist) (if (null? alist) (list1 (list2 x y)) (if (equal? x (caar alist)) (cons (list2 x y) (cdr alist)) (cons (car alist) (bind x y (cdr alist)))))) c Copyright 2006 Norman Ramsey. All Rights Reserved. 6 To change office from list to symbol: (set nr (bind ’Office ’Maxwell-Dworkin-231 nr)) nr 152 Email [email protected] Course Office 231 Maxwell-Dworkin c Copyright 2006 Norman Ramsey. All Rights Reserved. 7 First recursive call: (bind x y (cdr alist)) nr alist 152 Email [email protected] Course Office 231 Maxwell-Dworkin c Copyright 2006 Norman Ramsey. All Rights Reserved. 8 Comparison succeeds: (cons (list2 x y) (cdr alist)) nr (list2 x y) (cdr alist) (cons ...) 152 Email [email protected] Office 231 Maxwell-Dworkin Course Office Maxwell-Dworkin-231 c Copyright 2006 Norman Ramsey. All Rights Reserved. 9 Now return, back to first call: (cons (car alist) (bind ...)) nr alist 152 Email [email protected] Office...
View Full Document

This note was uploaded on 02/13/2012 for the course CS 91.531 taught by Professor Giam during the Fall '09 term at UMass Lowell.

Page1 / 45

GarbageCollection - Implementing functions Expressive Power First-class Functions Programmer’s Productivity Implementation c Copyright 2006

This preview shows document pages 1 - 11. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online