473,325 Members | 2,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Desrtuctor WOES, was Advice on __del__

> you haven't answered my question, btw: why are you using __del__
to do something that the garbage collector should do for you?

After more reading it seems I have made an ass of my self on this
subject. Here is my problem at length.

I teach high school geometry. I have created a program with a
scalable graph on which to make drawings to illustrate concepts.
This is working well.
I like to MOVE the objects one pixel at a time or ROTATE them
one degree at a time so the students can follow the progress of
the lesson.

A script of a simple drawing might be:

scale 100
color red
tr1 = triangle from x y base baselength angles 30 60
rotate centerx centery degrees objlist # eg tr1

This would create an instance of triangle which would
create an instance of polygon which would create 3
instances of lines, which are point pairs.

class line:
def __init__(s,glob,argl,color=''):
s.glob = glob
:::
:::

x0 = a0 * s.glob.scale + 400
y0 = 300 - b0 * s.glob.scale
x1 = a1 * s.glob.scale + 400
y1 = 300 - b1 * s.glob.scale
s.obj = glob.can.create_line(x0,y0,x1,y1,
width=glob.width,fill=s.color)
def __del__(s):
s.glob.can.delete(s.obj)

This calls Canvas.create_line. Tkinter keeps its own list of
drawn objects. I store the ref in s.obj

NOW when I rotate the triangle 45 degrees, recomputing the points
each time, it creates 45 new instances of triangle but dels the
old one. __del__ then deletes the Canvas line object.

Without that, the list of objects grows very long,
and refresh gets slow.
This is a very complex program, 1000 lines now, propably 2000
lines eventually. There are dozens of places where I depend on
__del__ deleteting canvas objects.

SO: without significant rewrite of each class such as triangle
and line, how can I ensure those canvas lines get deleted?
You don't really need to understand Canvas, just trust me
I have to delete those objects and they are not properties of the
class which go away with garbage collection.

Thanks.

Jul 19 '05 #1
0 1118

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: seth | last post by:
Last week I encountered an AttributeError in my unit tests that I wasn'table to catch with an "except AttributeError" statement. The problem stemmed from a class that raised an error inside...
2
by: Kepes Krisztian | last post by:
Hi ! I very wonder, when I get exp. in java with GC. I'm Delphi programmer, so I get used to destructorin objects. In Java the final method is not same, but is like to destructor (I has...
6
by: Peter Abel | last post by:
I have an application, which is an instance of a class with a deeply nested object hierarchy. Among others one method will be executed as a thread, which can be stopped. Everything works fine...
13
by: Emmanuel | last post by:
Hi, I run across this problem, and couldn't find any solution (python 2.2.2) : Code : =========== from __future__ import generators >>> class titi:
1
by: schwerdy | last post by:
Hello developers! I'm using Python 2.3.4 under debian Sarge and want to write a small logger class. My source code reads: #*************************************************** import sys, time...
2
by: Daniel Bickett | last post by:
Hello, I am writing an application using two event-driven libraries: wxPython, and twisted. The first problem I encountered in the program is the confliction between the two all-consuming...
2
by: Mike C. Fletcher | last post by:
I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate __del__ methods (and the memory leaks they create). Looking at the docs for 2.3's weakref.ref, there's no mention of whether...
1
by: Erwan Adam | last post by:
Hello all, Can someone reproduce this bug ... I use : python Python 2.4.3 (#2, Sep 18 2006, 21:07:35) on linux2 Type "help", "copyright", "credits" or "license" for more information. ...
6
by: George Sakkis | last post by:
I'm baffled with a situation that involves: 1) an instance of some class that defines __del__, 2) a thread which is created, started and referenced by that instance, and 3) a weakref proxy to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.