Re: Question About When Objects Are Destroyed (continued)

2017-08-07 Thread Grant Edwards
On 2017-08-05, Tim Daneliuk wrote: > On 08/05/2017 03:21 PM, Chris Angelico wrote: >> so the object's lifetime shouldn't matter to you. > > I disagree with this most strongly. That's only true when the > machine resources being consumed by your Python object are small in >

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:36 PM, Ned Batchelder wrote: > On 8/5/17 5:41 PM, Tim Daneliuk wrote: >> On 08/05/2017 11:16 AM, Ned Batchelder wrote: >>> It uses >>> reference counting, so most objects are reclaimed immediately when their >>> reference count goes to zero, such as at the end of local scopes. >>

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:36 PM, Ned Batchelder wrote: > On 8/5/17 5:41 PM, Tim Daneliuk wrote: >> On 08/05/2017 11:16 AM, Ned Batchelder wrote: >>> It uses >>> reference counting, so most objects are reclaimed immediately when their >>> reference count goes to zero, such as at the end of local scopes. >>

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:58 PM, Chris Angelico wrote: > On Sun, Aug 6, 2017 at 7:32 AM, Tim Daneliuk wrote: >> On 08/05/2017 03:21 PM, Chris Angelico wrote: >>> After a 'with' block, >>> the object *still exists*, but it has been "exited" in some way >>> (usually by closing/releasing

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 05:58 PM, Chris Angelico wrote: > On Sun, Aug 6, 2017 at 7:32 AM, Tim Daneliuk wrote: >> On 08/05/2017 03:21 PM, Chris Angelico wrote: >>> After a 'with' block, >>> the object *still exists*, but it has been "exited" in some way >>> (usually by closing/releasing

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Chris Angelico
On Sun, Aug 6, 2017 at 7:32 AM, Tim Daneliuk wrote: > On 08/05/2017 03:21 PM, Chris Angelico wrote: >> After a 'with' block, >> the object *still exists*, but it has been "exited" in some way >> (usually by closing/releasing an underlying resource). > > The containing object

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Ned Batchelder
On 8/5/17 5:41 PM, Tim Daneliuk wrote: > On 08/05/2017 11:16 AM, Ned Batchelder wrote: >> It uses >> reference counting, so most objects are reclaimed immediately when their >> reference count goes to zero, such as at the end of local scopes. > Given this code: > > class SomeObject: > . >

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread MRAB
On 2017-08-05 22:41, Tim Daneliuk wrote: On 08/05/2017 11:16 AM, Ned Batchelder wrote: It uses reference counting, so most objects are reclaimed immediately when their reference count goes to zero, such as at the end of local scopes. Given this code: class SomeObject: . for foo

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Marko Rauhamaa
Tim Daneliuk : > Are you saying that each time a,b,c are reassigned to new instances of > SomeObject the old instance counts go to 0 and are immediately - as in > synchronously, right now, on the spot - removed from memory? That depends on the implementation of Python.

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 11:16 AM, Ned Batchelder wrote: > It uses > reference counting, so most objects are reclaimed immediately when their > reference count goes to zero, such as at the end of local scopes. Given this code: class SomeObject: . for foo in somelist: a = SomeObject(foo) b

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/05/2017 03:21 PM, Chris Angelico wrote: > After a 'with' block, > the object *still exists*, but it has been "exited" in some way > (usually by closing/releasing an underlying resource). The containing object exists, but the things that the closing logic explicitly released do not. In some

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Chris Angelico
On Sun, Aug 6, 2017 at 1:23 AM, Tim Daneliuk wrote: > On 08/04/2017 07:00 PM, Chris Angelico wrote: >> Again, don't stress about exactly when objects get >> disposed of; it doesn't matter. > > > Respectfully, I disagree strongly. Objects get build on the heap and > persist

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Ned Batchelder
On 8/5/17 11:23 AM, Tim Daneliuk wrote: > On 08/04/2017 07:00 PM, Chris Angelico wrote: >> Again, don't stress about exactly when objects get >> disposed of; it doesn't matter. > > Respectfully, I disagree strongly. Objects get build on the heap and > persist even when they go out of scope until

Re: Question About When Objects Are Destroyed

2017-08-05 Thread Ned Batchelder
On 8/4/17 7:42 PM, Jon Forrest wrote: > On 8/4/2017 4:34 PM, gst wrote: >> 'two' is a so called constant or literal value .. (of that >> function). >> >> Why not attach it, as a const value/object, to the function itself ? >> So that a new string object has not to be created each time the >>

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Marko Rauhamaa
Tim Daneliuk : > On 08/04/2017 07:00 PM, Chris Angelico wrote: >> Again, don't stress about exactly when objects get disposed of; it >> doesn't matter. > > Respectfully, I disagree strongly. Objects get build on the heap and > persist even when they go out of scope until such

Re: Question About When Objects Are Destroyed (continued)

2017-08-05 Thread Tim Daneliuk
On 08/04/2017 07:00 PM, Chris Angelico wrote: > Again, don't stress about exactly when objects get > disposed of; it doesn't matter. Respectfully, I disagree strongly. Objects get build on the heap and persist even when they go out of scope until such time garbage collection takes place. This

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Terry Reedy
On 8/4/2017 7:11 PM, Jon Forrest wrote: Consider the following Python shell session (Python 3.6.2, Win64): >>> def givemetwo(): ... x = 'two' ... print(id(x)) ... >>> givemetwo() 1578505988392 So far fine. My understanding of object existence made me think that the object

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Steve D'Aprano
On Sat, 5 Aug 2017 09:11 am, Jon Forrest wrote: > Consider the following Python shell session (Python 3.6.2, Win64): > > >>> def givemetwo(): > ... x = 'two' > ... print(id(x)) > ... > >>> givemetwo() > 1578505988392 > > So far fine. My understanding of object existence made

Re: Question About When Objects Are Destroyed (continued)

2017-08-04 Thread Chris Angelico
On Sat, Aug 5, 2017 at 9:47 AM, Jon Forrest wrote: > Perhaps the reason the variable isn't destroyed is > shown by the following (again, in the same session): > import sys sys.getrefcount(1578505988392) > 3 > > So, maybe it's not destroyed because there are still >

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Chris Angelico
On Sat, Aug 5, 2017 at 9:42 AM, Jon Forrest wrote: > On 8/4/2017 4:34 PM, gst wrote: >> >> 'two' is a so called constant or literal value .. (of that >> function). >> >> Why not attach it, as a const value/object, to the function itself ? >> So that a new string object has not

Re: Question About When Objects Are Destroyed

2017-08-04 Thread Jon Forrest
On 8/4/2017 4:34 PM, gst wrote: 'two' is a so called constant or literal value .. (of that function). Why not attach it, as a const value/object, to the function itself ? So that a new string object has not to be created each time the function is called. Because anyway strings are immutable. So