August 2001
Beginner
482 pages
10h 52m
English
When your program allocates memory on the heap, a pointer is returned. It is imperative that you keep a pointer to that memory, because after the pointer is lost, the memory cannot be deleted and becomes a memory leak.
As you pass this block of memory between functions, one of the functions will “own” the pointer. Typically the value in the block will be passed using references, and the function that created the memory block is the one that deletes it. But this is a general rule, not an ironclad one.
It is dangerous for one function to create space in memory and another to free it, however. Ambiguity about which owns the pointer can lead to one of two problems: forgetting to delete a pointer or deleting ...
Read now
Unlock full access