Problems with Pointer - and Some Solutions

Three Possible Kinds of Errors

Null Pointers

Error 1: Null Pointers

Null Exclusion

Null Exclusion in Type Declarations

Null Exclusion in Parameter Declarations

Garbage Creation and Memory Leak

Garbage: Definition, and the Freelist

Error 2: Creating Garbage

Garbage Collection and Memory Leaks

Garbage, Explicit Deallocation, and the Freelist

Avoid Garbage with Explicit Deallocation of Memory

Stack-Based Allocation

Storage Pools

Dangling References (and Aliases)

Error 3: Dangling References


Dangling References

Dangling References and Reallocated Memory

Dangling References and Reallocation of Different Types

Avoiding Dangling References

Avoiding Dangling References with Aliases

Summary of Errors