Re: What does del actually do?

2007-02-13 Thread Bruno Desthuilliers
John Nagle a écrit :
The Python reference manual says, for del, Rather that spelling 
 it out in full details, here are some hints.  That's not too helpful.
 
In particular, when del is applied to a class object, what happens?
 Are all the instance attributes deleted from the object?  

It would have been simpler to just test:
  class Ghost(object):
... def __init__(self, name):
... self.name = name
... say = whoo
... def greetings(self):
... print %s from %s %s \
... %(self.say, self.__class__.__name__, self.name)
...
  g1 = Ghost(Albert)
  g2 = Ghost(Ivan)
  g1.greetings()
whoo from Ghost Albert
  del Ghost
  g1.greetings()
whoo from Ghost Albert
  g1.__class__
class '__main__.Ghost'
 

the del statement remove a name from the current namespace. period. It's 
also used for removing keys from dicts.

 Is behavior
 the same for both old and new classes?

Should it be different ?

I'm trying to break cycles to fix some memory usage problems.

GC and/or Weakrefs should do.
-- 
http://mail.python.org/mailman/listinfo/python-list


What does del actually do?

2007-02-10 Thread John Nagle
The Python reference manual says, for del, Rather that spelling it out 
in full details, here are some hints.  That's not too helpful.

In particular, when del is applied to a class object, what happens?
Are all the instance attributes deleted from the object?  Is behavior
the same for both old and new classes?

I'm trying to break cycles to fix some memory usage problems.

John Nagle
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does del actually do?

2007-02-10 Thread Calvin Spealman
del simply removes the name in the current scope. if that happens to
be the last non-cyclic reference to the object it was bound to, then
it will remove the objec to, but thats a seperate matter. if you
remove the class and there are instances out there, they can only
exist if there are some other references to them, so no, they arent
deleted.

del wont just delete a bunch of objects and leave broken names. i has
nothing to do with deleting objects, only names.

On 2/10/07, John Nagle [EMAIL PROTECTED] wrote:
 The Python reference manual says, for del, Rather that spelling it 
 out
 in full details, here are some hints.  That's not too helpful.

 In particular, when del is applied to a class object, what happens?
 Are all the instance attributes deleted from the object?  Is behavior
 the same for both old and new classes?

 I'm trying to break cycles to fix some memory usage problems.

 John Nagle
 --
 http://mail.python.org/mailman/listinfo/python-list



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: What does del actually do?

2007-02-10 Thread Steve Holden
Calvin Spealman wrote [top-posting, which I have corrected]:
 On 2/10/07, John Nagle [EMAIL PROTECTED] wrote:
 The Python reference manual says, for del, Rather that spelling it 
 out
 in full details, here are some hints.  That's not too helpful.

 In particular, when del is applied to a class object, what happens?
 Are all the instance attributes deleted from the object?  Is behavior
 the same for both old and new classes?

 I'm trying to break cycles to fix some memory usage problems.

  del simply removes the name in the current scope. if that happens to
  be the last non-cyclic reference to the object it was bound to, then
  it will remove the object to, but thats a separate matter. if you
  remove the class and there are instances out there, they can only
  exist if there are some other references to them, so no, they arent
  deleted.
 
  del wont just delete a bunch of objects and leave broken names. i has
  nothing to do with deleting objects, only names.
 
Except, of course, when you aren't deleting names but elements of some 
container object.

The del statement removes references to objects as well as removing 
names from namespaces and elements from container objects. Calvin is 
correct, though. Since each instance of a class contains a reference to 
the class, the class will live on even after it is deleted by name, 
being garbage-collected only after all instances have ceased to exist.

regards
  Steve
-- 
Steve Holden   +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd  http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note:  http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007

-- 
http://mail.python.org/mailman/listinfo/python-list