Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103930

Re: How to know if an object is still be referenced?

Newsgroups comp.lang.python
Date 2016-03-02 18:36 -0800
References <8e9f1a84-cced-435e-a379-e1e2ac03f483@googlegroups.com> <mailman.95.1456902233.20602.python-list@python.org> <c0cd3360-c19f-4c83-a54d-8fb3b1f329e7@googlegroups.com> <2c2f1a47-af1b-41b6-a127-9020d1452586@googlegroups.com>
Message-ID <39a1772e-cb54-4148-bd5b-403ca2abb52b@googlegroups.com> (permalink)
Subject Re: How to know if an object is still be referenced?
From jfong@ms4.hinet.net

Show all headers | View raw


sohca...@gmail.com at 2016/3/3  UTC+8 7:38:45AM wrote:
> "label" might be a local variable, but it's constructor includes a reference to the frame in which it is going.  The frame object will create a reference to the newly-created Label object.  At that point, there will be two references to the new Label object.  When the function exits and "label" goes out of scope, the object still exists because the frame still has a reference.
> 
It sound reasonable enough:-)

There is a page talking about why should keep a separate reference in tkinter.
http://effbot.org/pyfaq/why-do-my-tkinter-images-not-appear.htm

I also saw almost every code on the web about it was written in this way:
    label = Label(playbar_frame, image=photo)
    label.image = photo
But why? Won't it be better if it was written as:
    label = Label(playbar_frame, image=photo)
    label.imgKeeper = photo
At least it makes the meaning more clear, not lead someone to a wrong direction:-(

Anyway, following Terry's suggestion might be a better idea, making it bind to an object which will live for as long as the application is.

--Jach

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

How to know if an object is still be referenced? jfong@ms4.hinet.net - 2016-03-01 18:35 -0800
  Re: How to know if an object is still be referenced? Terry Reedy <tjreedy@udel.edu> - 2016-03-02 02:03 -0500
    Re: How to know if an object is still be referenced? jfong@ms4.hinet.net - 2016-03-02 03:35 -0800
      Re: How to know if an object is still be referenced? sohcahtoa82@gmail.com - 2016-03-02 15:38 -0800
        Re: How to know if an object is still be referenced? jfong@ms4.hinet.net - 2016-03-02 18:36 -0800

csiph-web