Why is Garbage Collection Necessary for Object-Oriented Programming?
Michael Spertus Geodesic Systems mps@geodesic.com There are several reasons why true object-oriented programming requires garbage collection. 1. Manual Memory Management Breaks Encapsulation. Program components frequently need knowledge of an entire program to determine the last use of an object and provide deletion. This makes reuse of the component nearly impossible. For example, methods and functions taking a container as an argument need to know of or make assumptions about the rest of the program to determine ownership of the objects in the container. Attempts to encapsulate memory management with reference counting, the “poor man’s garbage collector”, are usually misguided. Reference counting has worse performance than GC, awkward syntax, and poor semantics, which typically include failure to reclaim cycles, inability to handle stack and static objects, lack of polymorphism, and problems with interior pointers (e.g. arrays and multiple inheritance). Intensive research [1] in garb