Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'none,': 0.05; 'executed': 0.07; 'python': 0.09; 'counting': 0.09; 'garbage': 0.09; 'referenced': 0.09; 'references,': 0.09; 'runtime': 0.09; 'subject:None': 0.09; 'variables,': 0.09; 'itself.': 0.11; 'subject:python': 0.11; 'library': 0.15; '"del"': 0.16; 'bryan': 0.16; 'chunks.': 0.16; 'executed,': 0.16; 'hierarchy': 0.16; 'processes.': 0.16; 'relevant,': 0.16; 'runs.': 0.16; 'subject: \n ': 0.16; 'tuple,': 0.16; 'utc,': 0.16; 'zero,': 0.16; 'wrote:': 0.17; 'pieces': 0.17; 'obviously': 0.18; 'memory': 0.18; 'variable': 0.20; 'bit': 0.21; 'os,': 0.22; 'subject:release': 0.22; 'wednesday,': 0.22; 'elements': 0.23; 'references': 0.23; 'so.': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'common': 0.26; 'am,': 0.27; 'separate': 0.27; 'object,': 0.27; "doesn't": 0.28; 'cycles': 0.29; 'piece': 0.29; 'str': 0.29; 'case,': 0.29; 'no,': 0.29; 'objects': 0.29; 'function.': 0.33; 'problem': 0.33; 'to:addr :python-list': 0.33; 'monitor': 0.33; 'another': 0.33; 'done': 0.34; 'list': 0.35; 'bigger': 0.35; 'there': 0.35; 'next': 0.35; 'list.': 0.35; 'created': 0.36; 'tool': 0.36; 'should': 0.36; 'subject: (': 0.36; 'turn': 0.36; 'itself': 0.37; 'does': 0.37; 'two': 0.37; 'uses': 0.37; 'quite': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'delete': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'release': 0.39; 'received:192': 0.39; 'little': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'subject:, ': 0.61; 'monitoring': 0.61; 'free': 0.61; 'deals': 0.62; 'behavior': 0.64; 'other.': 0.64; 'choose': 0.65; 'box.': 0.65; 'sound': 0.65; 'subject: ': 0.66; 'received:74.208': 0.71; 'counts': 0.81; 'discovered': 0.83; '2.7.1': 0.84; '2013': 0.84; 'actually,': 0.84; 'parcels': 0.84; 'utilized': 0.84; 'glance': 0.91; 'subject:Set': 0.91; 'subject:del': 0.91; 'whereby': 0.91 Date: Wed, 06 Mar 2013 08:18:00 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130221 Thunderbird/17.0.3 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Set x to to None and del x doesn't release memory in python 2.7.1 (HPUX 11.23, ia64) References: <390f0dc5-5750-4849-9433-a19d90cc8566@googlegroups.com> <87zjyhhret.fsf@nautilus.nautilus> <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> In-Reply-To: <18272cff-cfb0-4bd3-8f5d-3b4641ba828e@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:guZyzNRqva4yT7b4Qk8AJSQuMmIz/ZCiLnlcWlLH3RI Zpzus/sYS7f94dILYMXeIBUJF1gy+sSxkcPUrlLCRxhAtbRViX 0FzlW/rW9OfAEzq2meG527SOKMmrShAoyO31m1QXG1WfIzRKdU 1W763SskR+COhlHHuEKekkx1b62+dcGo5L/z4oSE2zQJFVMMrv La4fHXTB92W6ykDLydPHEABUgUCFPMiaIeoW5ruyYAgDC18aUP Q0vOlWhv5VyfHwMpJUg+2byv52ZmMLoYTsbLPnTjAGwkjODHsl XmEDB05/hHs62xvmEht0SozrnN9DKHC3YkJUlDl/ZzYO3lBfA= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362575899 news.xs4all.nl 6950 [2001:888:2000:d::a6]:44948 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40633 On 03/06/2013 05:25 AM, Bryan Devaney wrote: > On Wednesday, March 6, 2013 10:11:12 AM UTC, Wong Wah Meng-R32813 wrote: >> Hello there, >> >> >> >> I am using python 2.7.1 built on HP-11.23 a Itanium 64 bit box. >> >> >> >> I discovered following behavior whereby the python process doesn't seem to release memory utilized even after a variable is set to None, and "deleted". I use glance tool to monitor the memory utilized by this process. Obviously after the for loop is executed, the memory used by this process has hiked to a few MB. However, after "del" is executed to both I and str variables, the memory of that process still stays at where it was. >> >> >> > > Python uses a 'garbage collector'. When you delete something, all references are removed from the object in memory, the memory itself will not be freed until the next time the garbage collector runs. When that happens, all objects without references in memory are removed and the memory freed. If you wait a while you should see that memory free itself. > Actually, no. The problem with monitoring memory usage from outside the process is that memory "ownership" is hierarchical, and each hierarchy deals in bigger chunks. So when the CPython runtime calls free() on a particular piece of memory, the C runtime may or may not actually release the memory for use by other processes. Since the C runtime grabs big pieces from the OS, and parcels out little pieces to CPython, a particular big piece can only be freed if ALL the little pieces are free. And even then, it may or may not choose to do so. Completely separate from that are the two mechanisms that CPython uses to free its pieces. It does reference counting, and it does garbage collecting. In this case, only the reference counting is relevant, as when it's done there's no garbage left to collect. When an object is no longer referenced by anything, its count will be zero, and it will be freed by calling the C library function. GC is only interesting when there are cycles in the references, such as when a list contains as one of its elements a tuple, which in turn contains the original list. Sound silly? No, it's quite common once complex objects are created which reference each other. The counts don't go to zero, and the objects wait for garbage collection. OP: There's no need to set to None and also to del the name. Since there's only one None object, keeping another named reference to that object has very little cost. -- DaveA