473,625 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Garbage collection working improperly?

Dear List,
Trying the following hack:
a = []
for i in range(0,9999999 ): a.append(i) del(a)


Builds up a great list in memory and immediately deletes it. Unfortunately
the task manager shows me that i allocated about 155MB in memory before
del(), but del only releases about 40MB of them so i'm leaving about 117 MB
of reserved memory after deleting the list.
I'm using python 2.2.3 on WinXP.
Any ideas about that? How can i dealloc the left memory space?
Best regards
Oliver
Jul 18 '05 #1
7 1464
Hi,
Builds up a great list in memory and immediately deletes it. Unfortunately
if all you want is to create a loop, use xrange instead of range - it
won't create that huge list.
the task manager shows me that i allocated about 155MB in memory before
del(), but del only releases about 40MB of them so i'm leaving about 117 MB
of reserved memory after deleting the list.
I'm using python 2.2.3 on WinXP.
Any ideas about that? How can i dealloc the left memory space?


Nope, no idea - the only thing that I can think of is that python not
necessarily releaseses the memory because it uses its own allocation
scheme. I don't know that for sure, but I definitely would go for such a
thingy if I was to implement a virtual machine.
Its like in JAVA - each object instantiation and destruction isn't
paired with system malloc/free calls, but some internal memory manager
deals with that. And if it rans out of space, it will request more from
the system.

Regards,

Diez

Jul 18 '05 #2
"Oliver Walczak" <ol************ @momatec.de> wrote in
news:ma******** *************** *************@p ython.org:
Builds up a great list in memory and immediately deletes it.
Unfortunately the task manager shows me that i allocated about 155MB
in memory before del(), but del only releases about 40MB of them so
i'm leaving about 117 MB of reserved memory after deleting the list.
I'm using python 2.2.3 on WinXP.
Any ideas about that? How can i dealloc the left memory space?


You cannot, but it shouldn't matter. If you aren't using it, then it will
eventually get paged out and occupy space in the swapfile, but the physical
memory will be allocated to other processed.

Small objects get handled specially by Python's memory allocation, and the
memory used for small objects will never be returned to the operating
system (until the process terminates). Its a trade off, because it means
that allocating the small objects is much faster, but the cost is extra
swap space used, not extra physical memory.

If it really matters to you to allocate a massive spike of memory then
release it all, you could try extracting the memory hungry code out into a
separate process that can terminate once it has finished whatever
calculation you are doing. That way all the memory really would be
released.

--
Duncan Booth du****@rcp.co.u k
int month(char *p){return(1248 64/((p[0]+p[1]-p[2]&0x1f)+1)%12 )["\5\x8\3"
"\6\7\xb\1\x9\x a\2\0\4"];} // Who said my code was obscure?
Jul 18 '05 #3
Diez B. Roggisch wrote:
Hi,
Builds up a great list in memory and immediately deletes it.
Unfortunately

if all you want is to create a loop, use xrange instead of range - it
won't create that huge list.
the task manager shows me that i allocated about 155MB in memory before
del(), but del only releases about 40MB of them so i'm leaving about
117 MB
of reserved memory after deleting the list.
I'm using python 2.2.3 on WinXP.
Any ideas about that? How can i dealloc the left memory space?

Nope, no idea - the only thing that I can think of is that python not
necessarily releaseses the memory because it uses its own allocation
scheme. I don't know that for sure, but I definitely would go for such
a thingy if I was to implement a virtual machine.
Its like in JAVA - each object instantiation and destruction isn't
paired with system malloc/free calls, but some internal memory manager
deals with that. And if it rans out of space, it will request more
from the system.


I kinda like VisualWorks Smalltalk's approach. It uses a system whereby
new objects are scavenged aggresivly and objects that survive the
scavenger are moved to a different memory space that is not GC'ed nearly
as much. (New objects tend to have short lives..objects that survive
several generations of scavenging tend to live longer) When it's memory
reaches a threshold, it makes a decision as to whether to either request
more from the OS or to GC the old object memory space in an attempt to
free more memory. The nice part is that you can configure a. how much
memory it starts with b. at what point the threshold is set for and
c.the weighting of the algorithim to determine whether to GC or allocate
Take care,
Jay

Jul 18 '05 #4
Oliver Walczak fed this fish to the penguins on Friday 21 November 2003
02:58 am:


Builds up a great list in memory and immediately deletes it.
Unfortunately the task manager shows me that i allocated about 155MB
in memory before del(), but del only releases about 40MB of them so
i'm leaving about 117 MB of reserved memory after deleting the list.
I'm using python 2.2.3 on WinXP.
Any ideas about that? How can i dealloc the left memory space?
I suspect the initial allocation is the OS assigning memory to the
process space. The del() is flagging that memory as free for reuse, but
not many OS runtimes are equipped to return freed memory to the OS (ie,
remove it from the process space). The stray 40MB may have been OS
related pointers to the occupied segments (if they had been allocated
in small chunks rather than one solid block); after the del() those
segment tracking pointers may have been freed to the OS, leaving just a
process header saying the process address space is n-MB long.

-- =============== =============== =============== =============== == <
wl*****@ix.netc om.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
=============== =============== =============== =============== == <
Bestiaria Home Page: http://www.beastie.dm.net/ <
Home Page: http://www.dm.net/~wulfraed/ <


Jul 18 '05 #5
In article <bp**********@r eader2.nmix.net >,
Jay O'Connor <jo******@cyber mesa.com> wrote:

I kinda like VisualWorks Smalltalk's approach. It uses a system whereby
new objects are scavenged aggresivly and objects that survive the
scavenger are moved to a different memory space that is not GC'ed nearly
as much. (New objects tend to have short lives..objects that survive
several generations of scavenging tend to live longer) When it's memory
reaches a threshold, it makes a decision as to whether to either request
more from the OS or to GC the old object memory space in an attempt to
free more memory. The nice part is that you can configure a. how much
memory it starts with b. at what point the threshold is set for and
c.the weighting of the algorithim to determine whether to GC or allocate


Python does the same thing -- you just can't configure it as much.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote
programs, then the first woodpecker that came along would destroy civilization.
Jul 18 '05 #6
Aahz wrote:
In article <bp**********@r eader2.nmix.net >,
Jay O'Connor <jo******@cyber mesa.com> wrote:

I kinda like VisualWorks Smalltalk's approach. It uses a system whereby
new objects are scavenged aggresivly and objects that survive the
scavenger are moved to a different memory space that is not GC'ed nearly
as much. (New objects tend to have short lives..objects that survive
several generations of scavenging tend to live longer) When it's memory
reaches a threshold, it makes a decision as to whether to either request
more from the OS or to GC the old object memory space in an attempt to
free more memory. The nice part is that you can configure a. how much
memory it starts with b. at what point the threshold is set for and
c.the weighting of the algorithim to determine whether to GC or allocate


Python does the same thing -- you just can't configure it as much.


I remember this in particular because I was working on an application
where the performance characteristics were such that for the most part
we wanted to allocate new memory rather than GC, but then as the memory
we were using reached a certain point, we wanted to free some of our own
cached objects so tha the GC could reclaim them. Being able to fine
tune the memory usage characteristics , and also hooking into
VisualWork's notification mechanism to be informed when GC was
happening, proved very important.

Jul 18 '05 #7
In article <bp**********@r eader2.nmix.net >,
Jay O'Connor <jo******@cyber mesa.com> wrote:
Aahz wrote:
In article <bp**********@r eader2.nmix.net >,
Jay O'Connor <jo******@cyber mesa.com> wrote:

I kinda like VisualWorks Smalltalk's approach. It uses a system whereby
new objects are scavenged aggresivly and objects that survive the
scavenger are moved to a different memory space that is not GC'ed nearly
as much. (New objects tend to have short lives..objects that survive
several generations of scavenging tend to live longer) When it's memory
reaches a threshold, it makes a decision as to whether to either request
more from the OS or to GC the old object memory space in an attempt to
free more memory. The nice part is that you can configure a. how much
memory it starts with b. at what point the threshold is set for and
c.the weighting of the algorithim to determine whether to GC or allocate


Python does the same thing -- you just can't configure it as much.


I remember this in particular because I was working on an application
where the performance characteristics were such that for the most part
we wanted to allocate new memory rather than GC, but then as the memory
we were using reached a certain point, we wanted to free some of our own
cached objects so tha the GC could reclaim them. Being able to fine
tune the memory usage characteristics , and also hooking into
VisualWork's notification mechanism to be informed when GC was
happening, proved very important.


Don't forget Python uses a very different memory management system. For
starters, Python's primary mechanism is refcounting rather than GC.
More than that, Python now uses PyMalloc as its standard allocation
system, which does a lot to reduce memory fragmentation. You can adjust
the frequency of GC in Python, but that's about it -- and you don't
really need much more than that, I think.
--
Aahz (aa**@pythoncra ft.com) <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote
programs, then the first woodpecker that came along would destroy civilization.
Jul 18 '05 #8

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

Similar topics

34
6403
by: Ville Voipio | last post by:
I would need to make some high-reliability software running on Linux in an embedded system. Performance (or lack of it) is not an issue, reliability is. The piece of software is rather simple, probably a few hundred lines of code in Python. There is a need to interact with network using the socket module, and then probably a need to do something hardware- related which will get its own driver written in C.
5
4772
by: R. MacDonald | last post by:
Hello, all, I am currently working on a .Net (VB) application that invokes routines in unmanaged (Fortran) DLLs. The unmanaged routines then communicate with the .Net application by means of a call-back mechanism. These calls pass a string that contains a "command" and a pointer to a SafeArray that (depending on the command) either receives data from the ..Net application or provides data to the .Net application. This mechanism is...
5
1809
by: R. MacDonald | last post by:
Hello, all, I am currently working on a .Net (VB) application that invokes routines in unmanaged (Fortran) DLLs. The unmanaged routines then communicate with the .Net application by means of a call-back mechanism. These calls pass a string that contains a "command" and a pointer to a SafeArray that (depending on the command) either receives data from the ..Net application or provides data to the .Net application. This mechanism is...
158
7786
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is discouraged due to some specific reason. If someone can give inputs on the same, it will be of great help. Regards, Pushpa
0
8253
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...
0
8189
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8692
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7182
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
6116
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
4089
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
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
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

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.