references and buffer()

Theerasak Photha hanumizzle at gmail.com
Sun Oct 8 16:16:07 EDT 2006


On 10/8/06, km <srikrishnamohan at gmail.com> wrote:
> Hi all,
>
>
> > Say that you copy the contents of file foo into file bar and delete
> > the original foo. Of course file bar still exists in this case. Not
> > much of a difference; I haven't seen buffer objects yet (I am also new
> > to Python), but the initialization for the buffer probably copies
> > whatever is in y somewhere.
>
>  that means when u refer to an object  with different names (variable), it
> referes to the same object- fine. but  is it that  the original object stays
> in memory until it is Garbage Collected ?

Exactly.

>  is it that  del() deletes  the link of variable to the object and not the
> object ? and thats why u can access it from other variables ?

Exactly.

> > You didn't modify the object that the variable /refers to/.
> > Furthermore, numbers are immutable anyway. To continue with the Hindu
> > god analogy, Vishnu did not cease to exist when any of his avatars
> > passed from the physical world; it is no different with objects in
> > Python.
>
>  vishnu analogy is a bit complicated as  it is a manifestation of divine
> energy in terms of earthly object(avatar). Its clearly not a reference. each
> avatar is himself (vishnu). It is the same energy people around have too
> (coz of manifestation). ofcourse they dont realise coz of ego (id in python)
>  and so the object class (divine energy) is the same - unlike python where
> we have different classes derived from object class.

Congratulations, you understand both Hinduism and Python better than I
do now.  :) c.f.
http://www.swami-krishnananda.org/brdup/brhad_III-09.html

"Kati references, Yajnavalkya, iti?"

(It is worth noting that a subclass is an instance of its superclass,
both in terms of interface and implementation.)

>  so the object exists until there are no references  to it and  will be
> Garbage Collected  immediately?

Python uses two garbage collection schemes together. It uses reference
counting (when number of references goes to zero, remove object from
memory) and mark-and-sweep (comb through process memory methodically
looking for objects that are no longer accessible). This is what
allows it to collect cyclic structures, such as trees whose nodes
links to their parents and vice versa.

GC intercedes at various intervals when convenient. I don't think it
would be immediate though.

-- Theerasak



More information about the Python-list mailing list