next up previous contents index
Next: 4.2 Object Protocol Up: 4.1 Introduction Previous: 4.1 Introduction

4.1.1 Memory Management

For all of the functions described in this chapter, if a function retains a reference to a Python object passed as an argument, then the function will increase the reference count of the object. It is unnecessary for the caller to increase the reference count of an argument in anticipation of the object's retention.

All Python objects returned from functions should be treated as new objects. Functions that return objects assume that the caller will retain a reference and the reference count of the object has already been incremented to account for this fact. A caller that does not retain a reference to an object that is returned from a function must decrement the reference count of the object (using DECREF(object)) to prevent memory leaks.



guido@cnri.reston.va.us