???Python Memory Management S***s???

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Apr 20 05:37:13 EDT 2008


On Sun, 20 Apr 2008 18:40:26 +1000, Hank @ITGroup wrote:

> In order to evaluate the memory operation, I used the codes below:
> 
> """
>  > string1 = ['abcde']*999999    # this took up an obvious memory space...
>  > del string1                              # this freed the memory 
> successfully !!

Indirectly.  ``del`` does not delete objects but just names, so you
deleted the name `string1` and then the garbage collector kicked in and
freed the list object as it was not reachable by other references anymore.

> """
> For primary variants, the *del* thing works well. However, challenge the 
> following codes, using class-instances...
> 
> """
>  > from nltk import FreqDist     # nltk stands for Natural Language Tool 
> Kit (this is not an advertisement ~_~)
>  > instance = FreqDist()
>  > instanceList = [instance]*99999
>  > del instanceList             # You can try: nothing is freed by this
> """

How do you know this?  And did you spot the difference between 999999 and
99999!?  Are you aware that both lists contain many references to a
*single* object, so the memory consumption has very little to do with the
type of object you put into the list?

In the second case you still hold a reference to that single instance
though.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list