[PyKDE] RE: strange bug in PyQt or python? (Tad E. Smith)

Toby Sargeant t.sargeant at inpharmatica.co.uk
Thu Jul 19 12:11:52 BST 2001


On Thu, Jul 19, 2001 at 12:00:05PM +0200, Tad E. Smith wrote:
> Gerard Vermeulen wrote:
<snip>
> > for item in list:
> >     Item(listView, item)

try changing this to:

list_view_items=[]
for item in list:
  list_view_items.append(Item(listView,item))

What's (probably) happening is that the python object is getting garbage
collected, but the list view is holding a pointer to the list view item, which
is holding a pointer to the python object, and so the python callback is
being called on an object that's already been free()'d. you're just being lucky
for a little while, and then as the number of new python objects you create
mounts, the probability that the unused memory will be reused and overwritten
with garbage (as far as the python object pointer is concerned) increases.
eventually, everything explodes.

unfortunately, this is a very hard problem to solve in general for fully
featured interfaces between c/c++ modules and python. sip does a good job,
but you still need to be careful to keep objects around while there are
references to them remaining in ``c++ space''.

-- 
   :flamer: n.	[common] One who habitually {flame}s.  Said esp. of
obnoxious {Usenet} personalities.

  [ Toby Sargeant : Inpharmatica : Developer : t.sargeant at inpharmatica.co.uk ]
      [ http://www.inpharmatica.co.uk : 020 7074 4600 fax 020 7631 4844 ]




More information about the PyQt mailing list