473,499 Members | 1,539 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 1457
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************************************@python .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.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\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.netcom.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**********@reader2.nmix.net>,
Jay O'Connor <jo******@cybermesa.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**@pythoncraft.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**********@reader2.nmix.net>,
Jay O'Connor <jo******@cybermesa.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**********@reader2.nmix.net>,
Jay O'Connor <jo******@cybermesa.com> wrote:
Aahz wrote:
In article <bp**********@reader2.nmix.net>,
Jay O'Connor <jo******@cybermesa.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**@pythoncraft.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
6356
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,...
5
4758
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...
5
1805
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...
158
7685
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...
0
7007
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
7171
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
7220
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...
1
6893
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...
1
4918
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...
0
4599
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...
0
3098
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...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
295
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...

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.