473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What does "del" actually do?

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
Feb 10 '07 #1
3 2563
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 <na***@animats.comwrote:
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/
Feb 10 '07 #2
Calvin Spealman wrote [top-posting, which I have corrected]:
On 2/10/07, John Nagle <na***@animats.comwrote:
> 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

Feb 10 '07 #3
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.
Feb 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: dananrg | last post by:
In PythonWin, is there any way to bulk-delete all objects without using "del object" for each, and without having to exit out of PythonWin?
2
by: Hank | last post by:
Apology for the previous offensive title~~ :) Thanks, Rintsch, Arnaud and Daniel, for replying so soon. I redid the experiment. What following is the record - ``starting python`` ...
0
by: Steve Holden | last post by:
Hank @ITGroup wrote: It doesn't really make that much sense to watch memory usage as you have been doing. Your first test case appears to trigger a specific pathology, where the memory allocator...
8
by: Ratko | last post by:
Say you have something like this: for item in myList: del item Would this actually delete the item from the list or just decrement the reference counter because the item in myList is not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.