wrongusername
wrongusername

Reputation: 18918

Deleting object in function

Let's say I have created two objects from class foo and now want to combine the two. How, if at all possible, can I accomplish that within a function like this:

def combine(first, second):
    first.value += second.value
    del second #this doesn't work, though first.value *does* get changed

instead of doing something like

def combine(first, second):
    first.value += second.value

in the function and putting del second immediately after the function call?

Upvotes: 1

Views: 242

Answers (1)

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798556

No. All del does against names is unbind them. This only removes the local reference. The object will be destroyed when there are no references to it anywhere, or all the references are in a reference loop.

Upvotes: 4

Related Questions