 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
| • |
Minimize
operations that return pointers to new heap
|
|
|
objects
|
|
|
|
• |
Doing
so would require the caller to (1) capture the returned
|
|
pointer
and (2) eventually deallocate the memory
|
|
|
| • |
Never
return a reference to a local stack object
|
|
|
|
• |
The
object is gone when the function exits
|
|
|
| • |
Never
return a reference to a newly allocated heap
|
|
|
object
|
|
|
|
• |
Deleting
the memory is not intuitive
|
|
|
| • |
Therefore,
only return a reference to an object that
|
|
|
exists
prior to the function call
|
|