Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!panix!not-for-mail From: Grant Edwards Newsgroups: comp.lang.python Subject: Re: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) Date: Mon, 11 Mar 2013 14:27:31 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 35 Message-ID: References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <5137d292$0$30001$c3e8da3$5496439d@news.astraweb.com> <78E1273CA6E76A43BB8830A194FF709B0B14D68C@039-SN2MPN1-013.039d.mgd.msft.net> <78E1273CA6E76A43BB8830A194FF709B0B153A71@039-SN2MPN1-013.039d.mgd.msft.net> NNTP-Posting-Host: dsl.comtrol.com X-Trace: reader2.panix.com 1363012051 23120 64.122.56.22 (11 Mar 2013 14:27:31 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 11 Mar 2013 14:27:31 +0000 (UTC) User-Agent: slrn/1.0.1 (Linux) Xref: csiph.com comp.lang.python:41063 On 2013-03-09, Roy Smith wrote: > In article , > Grant Edwards wrote: > >> What I should have said was that there's no way to return to the OS >> memory obtained via calls to malloc() et al. > > That's true (for certain values of "et al"). > >> and those are the calls that "good" C programmers (like the >> maintainers of CPython) use. > > Well, there is mmap, which is exposed via the Python mmap module. > Python doesn't have anything like C++'s "placement new", so there's > no way to use that memory to hold generic Python objects, but you can > certainly use mmap to allocate a large chunk of memory, use it, and > then give it back to the OS. [example] I was surprised to find that the object returned by mmap.mmap() supported file semantics (seek, tell, read, etc.) in addition to byte buffer semantics. Usually, the reason one maps a file is that one doesn't want to use file semantics (which are already supported by the file object) but wants instead to use buffer semantics. Using memmap to obtain a "returnable" chunk of memory seems a bit obtuse, since it requires creating an underlying file of appropriate size that ends up being superfluous. -- Grant Edwards grant.b.edwards Yow! I wonder if I ought at to tell them about my gmail.com PREVIOUS LIFE as a COMPLETE STRANGER?