1 / 12

Garbage Collection

Garbage Collection. records not reachable reclaim to allow reuse performed by runtime system (support programs linked with the compiled code). Record Types. live – will be used in the future not live – will not be used in the future reachable – able to be accessed via programs.

claubach
Télécharger la présentation

Garbage Collection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Garbage Collection • records not reachable • reclaim to allow reuse • performed by runtime system (support programs linked with the compiled code)

  2. Record Types • live – will be used in the future • not live – will not be used in the future • reachable – able to be accessed via programs

  3. Types of Algorithms • Mark-And-Sweep Collection • Reference Counts • Copying Collection • Generational Collection • Incremental Collection • Baker’s Algorithm

  4. Mark-And-Sweep Collection • Program variables and heap records form a directed graph • Roots are the variables • node n is reachable if r -> … -> n • Depth first search marks reachable nodes • Any node not marked is garbage

  5. Cost of Garbage Collection • Depth first search takes time proportional to the number of reachable nodes • Sweep phase takes time proportional to the size of the heap

  6. Maintaining Free Space • Create a list of free space • Search for a space of size N might be long • Maintain several free lists of differing sizes • External fragmentation a problem • Internal fragmentation can also be a problem

  7. Reference Counts • Count the number of pointers point to each record • Store the reference count with each record • If p addresses an alternate record, decrement the old and increment the new • If count reaches 0, free record

  8. When to Decrement Instead of decrementing the counts a record references when the record is placed on the free list, it is better to do this when the record is removed from the free list.

  9. Why • Breaks the recursive decrementing work into shorter pieces • Compiler emits code to check whether the count has reached 0, but the recursive decrementing will be done only in one place, in the allocator

  10. Problems with Reference Count • Cycles of garbage cannot be reclaimed • Incrementing the reference counts is very expensive

  11. Solutions-Cycles, Expensive • Require the programmer to break the cycle • Combine reference counting with mark-sweep • No solution for it being expensive • Problems outweigh advantages, thus rarely used

  12. Copying Collection • Reachable part is a directed graph with records as nodes, pointers as edges, and variables as roots • Copy the graph from “from-space” to “to-space” • Delete all “from-space”qq

More Related