473,589 Members | 2,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deleting objects on the fly

Hello,

I wish to know whether I should delete objects created on the fly via
the "del obj" statement. I noticed the RAM usage increased whenever
the application is being run for a long time. I am creating lots of
objects (messages) on the fly for communication between threads.

Rather than having python's gc to do the work, does it make a
difference if I force a deletion?

Thanks.

Aug 10 '07 #1
6 1356
On Aug 10, 2:25 am, Godzilla <godzillais...@ gmail.comwrote:
Hello,

I wish to know whether I should delete objects created on the fly via
the "del obj" statement. I noticed the RAM usage increased whenever
the application is being run for a long time. I am creating lots of
objects (messages) on the fly for communication between threads.

Rather than having python's gc to do the work, does it make a
difference if I force a deletion?

Thanks.
Probably not, 'del x' just decrements the reference count, but
it is the gc who does the real job. See http://docs.python.org/ref/customization.html#l2h-175

Do you have reference cycles in your application? You should
tell us something more.

Michele Simionato

Aug 10 '07 #2
Michele Simionato wrote:
On Aug 10, 2:25 am, Godzilla <godzillais...@ gmail.comwrote:
>Hello,

I wish to know whether I should delete objects created on the fly via
the "del obj" statement. I noticed the RAM usage increased whenever
the application is being run for a long time. I am creating lots of
objects (messages) on the fly for communication between threads.

Rather than having python's gc to do the work, does it make a
difference if I force a deletion?

Thanks.

Probably not, 'del x' just decrements the reference count, but
it is the gc who does the real job. See http://docs.python.org/ref/customization.html#l2h-175

Do you have reference cycles in your application? You should
tell us something more.

Michele Simionato
del x will remove x from memory if nothing else is refering to it, but
this dosnt really take the load off the GC since the GC will still check
the references and remove if there are none.

In some cases you could use to save ram...

a = 'really big string'
....do stuff with a...
del a

b = 'another really big string'
....do stuff with b...
del b
in the case that 'a' is not needed, after its used, and you dont want to
re-use the variable name. then del will free some ram since they both
wont need to exist at the same time.

WHen I say free ram, python its self will probably keep the ram for
later use but at least it wont need a and b in memory at once, so its
likely not to use as much ram.

But be careful using del in a loop since it can slow things down, its
like adding and removing an item from a dictionary many times. your
better off just redefining that variable or using del after the loops
finished.

Aug 10 '07 #3

"Campbell Barton" <cb*****@metavr .comwrote in message
news:46******** ******@metavr.c om...
| Michele Simionato wrote:
| Probably not, 'del x' just decrements the reference count,

Or as
http://docs.python.org/ref/del.html
puts it, " Deletion of a name removes the binding of that name from the
local or global namespace,"

| del x will remove x from memory if nothing else is refering to it,

This is implementation dependent: true for CPython, not for Jython, ??? for
IronPython.

tjr

Aug 10 '07 #4
On Aug 10, 1:49 pm, "Terry Reedy" <tjre...@udel.e duwrote:
"Campbell Barton" <cbar...@metavr .comwrote in message

news:46******** ******@metavr.c om...| Michele Simionato wrote:

| Probably not, 'del x' just decrements the reference count,

Or ashttp://docs.python.org/ref/del.html
puts it, " Deletion of a name removes the binding of that name from the
local or global namespace,"

| del x will remove x from memory if nothing else is refering to it,

This is implementation dependent: true for CPython, not for Jython, ??? for
IronPython.
Wait a second; do you mean to say that in Jython, del x will never
remove x from memory? How do you free up RAM?

Aug 11 '07 #5
Dustan <Du**********@g mail.comwrites:
| del x will remove x from memory if nothing else is refering to it,
This is implementation dependent: true for CPython, not for Jython, ??? for
IronPython.
Wait a second; do you mean to say that in Jython, del x will never
remove x from memory? How do you free up RAM?
It stays around until the GC picks it up.
Aug 11 '07 #6
Dustan wrote:
On Aug 10, 1:49 pm, "Terry Reedy" <tjre...@udel.e duwrote:
>"Campbell Barton" <cbar...@metavr .comwrote in message

news:46******* *******@metavr. com...| Michele Simionato wrote:

| Probably not, 'del x' just decrements the reference count,

Or ashttp://docs.python.org/ref/del.html
puts it, " Deletion of a name removes the binding of that name from the
local or global namespace,"

| del x will remove x from memory if nothing else is refering to it,

This is implementation dependent: true for CPython, not for Jython, ??? for
IronPython.

Wait a second; do you mean to say that in Jython, del x will never
remove x from memory? How do you free up RAM?
Because the exact method of garbage collection is independent of the
language definition, Jython uses the Java garbage collector, which works
(approximately) as follows.

In that language memory is allocated until a request cannot be
satisfies, then a scan is performed for unreferenced objects whose space
is reclaimed. Only if this doesn't yield enough space to allocate the
new object is more memory requested from the OS by the process.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------

Aug 11 '07 #7

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

Similar topics

2
519
by: Thomas Philips | last post by:
I'm teaching myself OOP using Michael Dawson's "Python Programming For The Absolute Beginner" and have a question about deleting objects. My game has two classes: Player and Alien, essentially identical, instances of which can shoot at each other. Player is described below class Player(object): #Class attributes for class Player n=0 #n is the number of players #Private methods for class Player
6
2029
by: Thomas Philips | last post by:
I have a question about deleting objects. My game has two classes, Player and Alien, essentially identical, instances of which can shoot at each other. Player is described below class Player(object): #Class attributes for class Player n=0 #n is the number of players #Private methods for class Player def __init__(self,name):
181
8741
by: Tom Anderson | last post by:
Comrades, During our current discussion of the fate of functional constructs in python, someone brought up Guido's bull on the matter: http://www.artima.com/weblogs/viewpost.jsp?thread=98196 He says he's going to dispose of map, filter, reduce and lambda. He's going to give us product, any and all, though, which is nice of him.
6
2428
by: Matan Nassau | last post by:
Hello. i have a composite which i want to delete. this is a composite which represents a boolean expression (see a previous post of mine with more details at http://groups.google.ca/groups?hl=en&lr=&ie=UTF-8&threadm=AXqqc.89218%24PJ1.865449%40wagner.videotron.net&rnum=1&prev=/groups%3Fq%3Dmatan%2Bnassau%26hl%3Den%26lr%3D%26ie%3DUTF-8%26sa%3DG%26scoring%3Dd ) VariableExp *x = new VariableExp("X"); VariableExp *y = new VariableExp("Y");...
9
1873
by: Aguilar, James | last post by:
Hey guys. A new question: I want to use an STL libarary to hold a bunch of objects I create. Actually, it will hold references to the objects, but that's beside the point, for the most part. Here's the question: I want to be able to change the references (including deleting them). Is there any way to do that besides using pointers rather than references for the STL library? I'd also prefer to avoid using const_cast, if it is indeed...
4
14010
by: al havrilla | last post by:
hi all what does the phrase: "scalar deleting destructor" mean? i'm getting this in a debug error message using c++ 7.1 thanks Al
51
10295
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
62
17693
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image(); img.src = ; Then I use the image a few more times by adding it into an Array object:
0
993
by: Terry Reedy | last post by:
"Jacob Davis" <j.foster.davis@gmail.comwrote in message news:C673A5C7-9971-4CAA-8CEB-3993C3E93F9C@gmail.com... | I read in some earlier messages that an object in Python is only | removed or freed from memory when all references to that object have | been deleted. Is this so? A Python interpreter *may* delete an object when, but only when, it becomes inaccessible from the currently running program. What interpreters do depends on the...
5
505
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store pointers of type structure "SAMPLE_TABLE_STRUCT" ( size of this structure is 36 bytes ). I create an instance of structure "SAMPLE_TABLE_STRUCT" using operator "new" and push back into the vector,this is done inside a for loop for
0
7931
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
7990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6637
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5731
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5399
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3849
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3889
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2374
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1198
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.