and which parts are garbage in particulara list is kept of all program variablesand any memory locations not reachable from one of these variables are considered to be garbage when the garbage collector executesall unused memory locations are placed in free store for future access this approach has the advantage that it allows for easy collection of garbage it has the disadvantagefrom user' point of viewthat every so often the system must halt while it performs garbage collection for examplegarbage collection is noticeable in the emacs text editorwhich is normally implemented in lisp occasionally the user must wait for moment while the memory management system performs garbage collection the java programming language also makes use of garbage collection as in lispit is common practice in java to allocate dynamic memory as neededand to later drop all references to that memory the garbage collector is responsible for reclaiming such unused space as necessary this might require extra time when running the programbut it makes life considerably easier for the programmer in contrastmany large applications written in +(even commonly used commercial softwarecontain memory leaks that will in time cause the program to fail several algorithms have been used for garbage collection one is the reference count algorithm hereevery dynamically allocated memory block includes space for count field whenever pointer is directed to memory blockthe reference count is increased whenever pointer is directed away from memory blockthe reference count is decreased if the count ever becomes zerothen the memory block is considered garbage and is immediately placed in free store this approach has the advantage that it does not require an explicit garbage collection phasebecause information is put in free store immediately when it becomes garbage the reference count algorithm is used by the unix file system files can have multiple namescalled links the file system keeps count of the number of links to each file whenever file is "deleted,in actuality its link field is simply reduced by one if there is another link to the filethen no space is recovered by the file system whenever the number of links goes to zerothe file' space becomes available for reuse reference counts have several major disadvantages firsta reference count must be maintained for each memory object this works well when the objects are largesuch as file howeverit will not work well in system such as lisp where the memory objects typically consist of two pointers or value (an atomanother major problem occurs when garbage contains cycles consider figure here each memory object is pointed to oncebut the collection of objects is still garbage because no pointer points to the collection thusreference counts only work when