Recitation - Feb 28, 2011
- new
- delete
- need to maintain at least one reference (e.g. pointer) to dynamically allocated memory
- lack of any reference to dynamically allocated memory is known as a memory leak
- data member(s) are typically used to link dynamically allocated memory to an object
- dynamically allocated member is typically located outside the object
- not automatically "cleaned up"
- generally a good idea to initialize pointers in the constructor.
- destructor commonly deallocates dynamically created memory.
- destructor is the last function that runs for an object
- Common steps for a dynamically allocated and resizeable array:
- new - create new array of desired size
- copy - copy old contents into new array
- delete - deallocate old array
- adjust pointers - assign array pointer to newly allocated array
- dlist (example)
Additional Notes
- new
- Can a call to new ever fail?
- Today counts as a participation grade (2pts)