[wxPython] wxPyGridTableBase - memory leak

If the script below is run with line 35 commented out, we get:

07:21:19 AM: There were memory leaks.

07:21:19 AM: ----- Memory dump -----

07:21:19 AM: wxGridTableBase at $15B94B8, size 32

07:21:19 AM:

07:21:19 AM:

07:21:19 AM: ----- Memory statistics -----

07:21:19 AM: 1 objects of class wxGridTableBase, total size 32

07:21:19 AM:

07:21:19 AM: Number of object items: 1

07:21:19 AM: Number of non-object items: 0

07:21:19 AM: Total allocated size: 32

07:21:19 AM:

07:21:19 AM:

Exit code: 1

With line 35 in play, we get a series (maybe 50) of line 31 errors:

value: ''Traceback (most recent call last):

File “_cPickle.py”, line 31, in GetValue

self.log.write('CrashIt: ' + 0)

TypeError: cannot add type “int” to string

value: ''Traceback (most recent call last):

File “_cPickle.py”, line 31, in GetValue

self.log.write('CrashIt: ' + 0)

TypeError: cannot add type “int” to string

These are followed by:

value: ''Traceback (most recent call
last):

File “_cPickle.py”, line
35, in ?

print '\nvalue:

’ +b.GetValue(0, 0)

File “_cPickle.py”, line
31, in GetValue

self.log.write('CrashIt:

’ + 0)

TypeError: cannot add type “int”
to string

and then by the memory leak report.

I would appreciate any advice.

Colin W.

···

_cPickle.py

import array, cPickle, exceptions

from wxPython.wx import *

from wxPython.grid import *

class Table(wxPyGridTableBase):

def __init__(self,

typeCodes, log):

wxPyGridTableBase.init(self)

self.log= log

self.newTable(typeCodes)

self.log.write('\ndir(self): ’ + dir(self))

self.log.write('\nvars(self): ’ + vars(self))

def newTable(self,

typeCodes= [‘d’]):

‘’’ initializeTable(typeCodes) → list of arrays

‘’’

self.nCols= len(typeCodes)

self.typeCodes= typeCodes

self.rowLabels=

self.colLabels=

if type(typeCodes) != type():

raise exceptions.TypeError, ‘typeCodes error’

a=

for i in range(self.nCols):

a.append(array.array(typeCodes[i]))

self.data= a

def GetValue(self,

row, col):

value= wxPyGridTableBase.GetValue(self, row, col)

self.log.write('\nvalue: ’ + value)

self.log.write('CrashIt: ’ + 0)

return ‘zzz’

b= Table([‘d’, ‘d’], sys.stdout)

print '\nvalue: ’ +b.GetValue(0, 0)

print 'b: ’ + b

If the script below is run with line 35 commented out, we get:

07:21:19 AM: There were memory leaks.
07:21:19 AM: ----- Memory dump -----
07:21:19 AM: wxGridTableBase at $15B94B8, size 32
07:21:19 AM:

Since your sample doesn't assign the table to a grid then it doesn't get
deleted automatically.

With line 35 in play, we get a series (maybe 50) of line 31 errors:

value: ''Traceback (most recent call last):
  File "_cPickle.py", line 31, in GetValue
    self.log.write('CrashIt: ' + 0)
TypeError: cannot add type "int" to string

Did you actually read this? What makes you think that assing strings and
ints should work?

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!