Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #44665
| X-Received | by 10.224.215.194 with SMTP id hf2mr16934508qab.0.1367580258997; Fri, 03 May 2013 04:24:18 -0700 (PDT) |
|---|---|
| X-Received | by 10.49.12.15 with SMTP id u15mr913984qeb.21.1367580258974; Fri, 03 May 2013 04:24:18 -0700 (PDT) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!l3no646257qak.0!news-out.google.com!y6ni0qax.0!nntp.google.com!m7no658805qam.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Fri, 3 May 2013 04:24:18 -0700 (PDT) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=93.34.49.96; posting-account=gxxH8QkAAABVKeYyAqGOGoaFtdDdsshI |
| NNTP-Posting-Host | 93.34.49.96 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <e09e5cf1-4df5-4e77-9108-32bc3a1ae07d@googlegroups.com> (permalink) |
| Subject | Trying to understand the memory occupation of big lists |
| From | Michele Simionato <michele.simionato@gmail.com> |
| Injection-Date | Fri, 03 May 2013 11:24:18 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:44665 |
Show key headers only | View raw
I have a memory leak in a program using big arrays. With the goal of debugging it I run into the memory_profiler module. Then I discovered something which is surprising to me. Please consider the following script:
$ cat memtest.py
import gc
from memory_profiler import profile
@profile
def test1():
a = [0] * 1024 * 1024
del a
gc.collect() # nothing change if I comment this
@profile
def test2():
for i in range(10):
a = [0] * 1024 * 1024
del a
gc.collect() # nothing change if I comment this
test1()
test2()
Here is its output, on a Linux 64 bit machine:
$ python memtest.py
Filename: memtest.py
Line # Mem usage Increment Line Contents
================================================
5 @profile
6 9.250 MB 0.000 MB def test1():
7 17.246 MB 7.996 MB a = [0] * 1024 * 1024
8 9.258 MB -7.988 MB del a
9 9.258 MB 0.000 MB gc.collect() # nothing change if I comment this
Filename: memtest.py
Line # Mem usage Increment Line Contents
================================================
12 @profile
13 9.262 MB 0.000 MB def test2():
14 17.270 MB 8.008 MB for i in range(10):
15 17.270 MB 0.000 MB a = [0] * 1024 * 1024
16 17.270 MB 0.000 MB del a
17 17.270 MB 0.000 MB gc.collect() # nothing change if I comment this
In the first case the memory is released (even if strangely not
completely, 7.996 != 7.988), in the second case the memory is not. Why it is so? I did expect gc.collect() to free the memory but it is completely ininfluent. In the second cases there are 10 lists with 8 MB each, so
80 MB are allocated and 72 released, but 8 MB are still there apparently.
It does not look like a problem of mem_profile, this is what observe with
top too.
Any ideas?
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Trying to understand the memory occupation of big lists Michele Simionato <michele.simionato@gmail.com> - 2013-05-03 04:24 -0700 Re: Trying to understand the memory occupation of big lists Dave Angel <davea@davea.name> - 2013-05-03 08:16 -0400 Re: Trying to understand the memory occupation of big lists Maarten <maarten.sneep@knmi.nl> - 2013-05-03 08:20 -0700
csiph-web