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?

X-Received by 10.107.10.217 with SMTP id 86mr485565iok.6.1456972592281; Wed, 02 Mar 2016 18:36:32 -0800 (PST)
X-Received by 10.50.102.106 with SMTP id fn10mr118412igb.5.1456972592258; Wed, 02 Mar 2016 18:36:32 -0800 (PST)
Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.glorb.com!hb3no10877063igb.0!news-out.google.com!k1ni6985igd.0!nntp.google.com!hb3no10877052igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Wed, 2 Mar 2016 18:36:31 -0800 (PST)
In-Reply-To <2c2f1a47-af1b-41b6-a127-9020d1452586@googlegroups.com>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=1.172.226.95; posting-account=G2sM6AoAAADOlDdo9rWD6sFkj3T5ULsz
NNTP-Posting-Host 1.172.226.95
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>
User-Agent G2/1.0
MIME-Version 1.0
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
Injection-Date Thu, 03 Mar 2016 02:36:32 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:103930

Show key headers only | 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