Re: ???Python Memory Management S***s???

2008-04-20 Thread Daniel Fetchinson
On 4/20/08, Hank @ITGroup [EMAIL PROTECTED] wrote:
 Hi, people!

 Greetings~
 These days I have been running a text processing program, written by
 python, of cause.
 In order to evaluate the memory operation, I used the codes below:

 
   string1 = ['abcde']*99# this took up an obvious memory space...
   del string1  # this freed the memory
 successfully !!

 
 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]*9
   del instanceList # You can try: nothing is freed by this
 
 ??? How do you people control python to free the memory in python 2.5 or
 python 2.4 ???
 Cheers!!!

I don't know about the others, I personally let the garbage collector
take care of it.

HTH,
Daniel
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ???Python Memory Management S***s???

2008-04-20 Thread Marc 'BlackJack' Rintsch
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']*99# 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]*9
   del instanceList # You can try: nothing is freed by this
 

How do you know this?  And did you spot the difference between 99 and
9!?  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
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ???Python Memory Management S***s???

2008-04-20 Thread Arnaud Delobelle
On Apr 20, 9:40 am, Hank @ITGroup [EMAIL PROTECTED] wrote:
 Hi, people!

 Greetings~
 These days I have been running a text processing program, written by
 python, of cause.
 In order to evaluate the memory operation, I used the codes below:

 
   string1 = ['abcde']*99    # this took up an obvious memory space...
   del string1                              # this freed the memory
 successfully !!

 
 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]*9
   del instanceList             # You can try: nothing is freed by this
 
 ??? How do you people control python to free the memory in python 2.5 or
 python 2.4 ???
 Cheers!!!

You mistyped your subject line; it should have read:

Help needed - I don't understand how Python manages memory

--
Arnaud

-- 
http://mail.python.org/mailman/listinfo/python-list