Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64)
Grant Edwards
invalid at invalid.invalid
Sat Mar 9 15:35:47 EST 2013
On 2013-03-09, Roy Smith <roy at panix.com> wrote:
> In article <khg1v3$l7q$1 at reader2.panix.com>,
> Grant Edwards <invalid at invalid.invalid> wrote:
>
>> In Unix there is no way to release heap memory (which is what you're
>> talking about) back to the OS except for terminating the process.
>
> That's not quite true. The man page for BRK(2) (at least on the Linux
> box I happen to have handy) says:
>
> "brk() and sbrk() change the location of the program break, which
> defines the end of the process's data segment (i.e., the program
> break is the first location after the end of the uninitialized data
> segment). Increasing the program break has the effect of allocating
> memory to the process; decreasing the break deallocates memory."
>
> So, in theory, it's possible.
Well spotted. I would have bet money (OK, not a lot), that sbrk()
only accepted positive increment values. I seem to have conflated
what sbrk() will accept and the fact that the C library's malloc/free
calls never call sbrk() with a nagative number.
[... nicely done demonstraction of negative sbrk() parameter usage ...]
> In practice, unless you go to extraordinary lengths (i.e. avoid
> almost all of the standard C library), the break is going to be
> managed by malloc(), and malloc() provides no way to give memory back
> (insert handwave here about mmap, and another handwave about various
> versions of malloc). But, that's due to the way malloc() manages its
> arena, not anything fundamental about how Unix works.
Indeed.
What I should have said was that there's no way to return to the OS
memory obtained via calls to malloc() et al, and those are the calls
that "good" C programmers (like the maintainers of CPython) use.
In theory, you could modify the C library so that calls to free()
might return memory to the OS. Sometimes. If you're lucky.
The problem is that if there's _one_byte_ of memory in use at the
"end" of the heap region, it doesn't matter if there's an unused 16GB
chunk in the middle -- it can't be returned to the OS.
--
Grant Edwards grant.b.edwards Yow! Look DEEP into the
at OPENINGS!! Do you see any
gmail.com ELVES or EDSELS ... or a
HIGHBALL?? ...
More information about the Python-list
mailing list