Re: [Beginner] delete items of [] also from memory

From: Duncan Booth (duncan.booth_at_invalid.invalid)
Date: 11/23/04


Date: 23 Nov 2004 09:47:45 GMT

Peter wrote:

> "Birgit Rahm" <br_y@yahoo.de> wrote in message
> news:<cns50t$5ip$05$1@news.t-online.com>...
>> Hello newsgroup,
>>
>> I am a beginner, so I am asking maybe immoderate questions.
>> I want to delete a [] variable, after filling it with complex
>> objects. How should I do it?
>> e.g.
>> AAA = []
>> AAA = [B, C, D, E, F]
>> Can I
>> 1) AAA = []
>> 2) del AAA[0:]
>> 3) ?
>> whats about the computers memory, will it get free? Or will it get
>> more and more while Python is running?
>
> I too am a novice, so am prepared to be corrected if this is wrong.
>
> I don't think you need to worry - Python handles memory allocation
> automatically. Names are not specifically allocated to memory, and
> when the last reference to a name is deleted all the associated memory
> is freed.

It depends on what the original poster meant by 'complex' objects.

Objects with circular references may not be freed until the garbage
collector kicks in, and objects with circular references and a __del__
method may not be freed at all. However, provided you avoid writing __del__
methods on such objects, the memory may not be freed immediately but it
will be freed eventually.

Objects which are not involved in any cyclic references will be freed, as
you say, as soon as the last reference goes.

('Freed' in this context means released for reuse by Python --- don't ever
expect the process to release memory back to the rest of the system.)



Relevant Pages

  • Re: Writing huge Sets() to disk
    ... > references in python. ... > state and taking say 600MB, pushes it's internal dictionaries ... Almost anything you do copies references. ... that this code takes a lot of extra memory. ...
    (comp.lang.python)
  • Re: [patch 1/6] mmu_notifier: Core code
    ... external references to pages managed by the Linux kernel. ... access memory managed by the Linux kernel. ... The MMU notifier will notify the device driver that subscribes to such ...
    (Linux-Kernel)
  • Re: [PHP] Odd PHP memory issue
    ... all references to the result variable are unset when I ... to see if the memory is getting chewed up in a straight line or if it ... Scope seems like it should be simple, ... posting this question was to find out more about how PHP internals work, ...
    (php.general)
  • Re: Finding the instance reference of an object
    ... "variable" is commonly thought of as a fixed location in memory ... dinosaurs and instead compare Python to any modern OOP language. ... variables are just names/aliases for *references* to ...
    (comp.lang.python)
  • Re: Finding the instance reference of an object
    ... "variable" is commonly thought of as a fixed location in memory ... dinosaurs and instead compare Python to any modern OOP language. ... Is there any way to prove that, without delving into the Python ... variables are just names/aliases for *references* to ...
    (comp.lang.python)

Loading