Memory leak

I have been - corectly informed that a program I have written has a
major memory leak. I think I have figured out why - everytime I update I
need to change the color of a drawn object. Instead I am overwriting the
display.

What I need to do is change my draw a hex code so that each hex can
later be referenced, and then change the shapes color.

Here are the chunks of code that are relavent to what I am working on.

def makehex(self,x,y):
  global colorarray,colormap
        plotx = x * 18
        ploty = y * 24
        if x%2 == 0:
            ploty = ploty + 12
        
        self.MyAddShape(HexShape(36, 36), plotx, ploty,
wxPen(wxColour(90,90,90), 2, wxDOT),colorarray[colormap[x][y]],"")

class HexShape(wxPolygonShape):
    def __init__(self, w=0.0, h=0.0):
        wxPolygonShape.__init__(self)
        if w == 0.0:
            w = 24.0
        if h == 0.0:
            h = 24.0

        points = [ (12,6,),
                   (6,18),
                   (12,30),
                   (24,30),
                   (30,18),
                   (24,6),
                   ]

        self.Create(points)

Mike Wagman wrote:

I have been - corectly informed that a program I have written has a
major memory leak. I think I have figured out why - everytime I update I
need to change the color of a drawn object. Instead I am overwriting the
display.

What I need to do is change my draw a hex code so that each hex can
later be referenced, and then change the shapes color.

Here are the chunks of code that are relavent to what I am working on.

I'll need a small as possible sample application that shows the same leak in order to track it down.

···

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

The problem is when I need to redraw the screen I call the routine that
creates all over again. I will work on getting an example together.

···

On Fri, 2003-11-28 at 17:52, Robin Dunn wrote:

Mike Wagman wrote:
> I have been - corectly informed that a program I have written has a
> major memory leak. I think I have figured out why - everytime I update I
> need to change the color of a drawn object. Instead I am overwriting the
> display.
>
> What I need to do is change my draw a hex code so that each hex can
> later be referenced, and then change the shapes color.
>
> Here are the chunks of code that are relavent to what I am working on.
>

I'll need a small as possible sample application that shows the same
leak in order to track it down.

Here is the code that is run after every move.

    for x in range(0,15):
        for y in range (0,15):
      if hexmap[y]==1:
                makehex(self,x,y)
                hextotal = hextotal+1
                score[playermap[y]]=score[playermap[y]]+1

So I suspect my problem is I keep drawing over the top of everything,

···

On Fri, 2003-11-28 at 19:09, Mike Wagman wrote:

The problem is when I need to redraw the screen I call the routine that
creates all over again. I will work on getting an example together.

On Fri, 2003-11-28 at 17:52, Robin Dunn wrote:
> Mike Wagman wrote:
> > I have been - corectly informed that a program I have written has a
> > major memory leak. I think I have figured out why - everytime I update I
> > need to change the color of a drawn object. Instead I am overwriting the
> > display.
> >
> > What I need to do is change my draw a hex code so that each hex can
> > later be referenced, and then change the shapes color.
> >
> > Here are the chunks of code that are relavent to what I am working on.
> >
>
> I'll need a small as possible sample application that shows the same
> leak in order to track it down.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail: wxPython-users-help@lists.wxwindows.org

Mike Wagman wrote:

Here is the code that is run after every move.

    for x in range(0,15):
        for y in range (0,15):
      if hexmap[y]==1:
                makehex(self,x,y)
                hextotal = hextotal+1
                score[playermap[y]]=score[playermap[y]]+1

So I suspect my problem is I keep drawing over the top of everything,

What does makehex do?

···

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

def makehex(self,x,y):
  global colorarray,colormap
        plotx = x * 18
        ploty = y * 24
        if x%2 == 0:
            ploty = ploty + 12
        
        self.MyAddShape(HexShape(36, 36), plotx, ploty,
wxPen(wxColour(90,90,90), 2, wxDOT),colorarray[colormap[y]],"")

and I suspect that is the culprit - I'm drawing the new moves over the
screen not redefining the objects on the screen.

···

On Mon, 2003-12-01 at 15:20, Robin Dunn wrote:

Mike Wagman wrote:
> Here is the code that is run after every move.
>
> for x in range(0,15):
> for y in range (0,15):
> if hexmap[y]==1:
> makehex(self,x,y)
> hextotal = hextotal+1
> score[playermap[y]]=score[playermap[y]]+1
>
> So I suspect my problem is I keep drawing over the top of everything,
>

What does makehex do?

Mike Wagman wrote:

def makehex(self,x,y):
  global colorarray,colormap
        plotx = x * 18
        ploty = y * 24
        if x%2 == 0:
            ploty = ploty + 12
                self.MyAddShape(HexShape(36, 36), plotx, ploty,
wxPen(wxColour(90,90,90), 2, wxDOT),colorarray[colormap[y]],"")

and I suspect that is the culprit - I'm drawing the new moves over the
screen not redefining the objects on the screen.

Yep. Specifically, you are creating new HexShapes and probably never destroying the old ones.

···

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

That what I thought - But how do I do either of the following.

Create each of these 200+ hexes with a unique ID - so I can destoy or
modify them.

Or wipe the whole lot out so I can redraw it.

I have been hitting the web sites and documentation but have not figured
it out yet.

···

On Tue, 2003-12-02 at 14:23, Robin Dunn wrote:

Mike Wagman wrote:
> def makehex(self,x,y):
> global colorarray,colormap
> plotx = x * 18
> ploty = y * 24
> if x%2 == 0:
> ploty = ploty + 12
>
> self.MyAddShape(HexShape(36, 36), plotx, ploty,
> wxPen(wxColour(90,90,90), 2, wxDOT),colorarray[colormap[y]],"")
>
> and I suspect that is the culprit - I'm drawing the new moves over the
> screen not redefining the objects on the screen.
>

Yep. Specifically, you are creating new HexShapes and probably never
destroying the old ones.

Mike Wagman wrote:

That what I thought - But how do I do either of the following.

Create each of these 200+ hexes with a unique ID - so I can destoy or
modify them.

Or wipe the whole lot out so I can redraw it.

I have been hitting the web sites and documentation but have not figured
it out yet.

What's wrong with holding a reference to all the HexShape objects in a Python list or some other data structure?

···

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

That is what I am trying to do, but I can't figure out how to get the
code happy. So once I create a hex how to I add it to a list. I may
fight with this some more -

···

What's wrong with holding a reference to all the HexShape objects in a
Python list or some other data structure?

I think I have figured out how to code this. Thanks

···

On Wed, 2003-12-03 at 15:40, Robin Dunn wrote:

Mike Wagman wrote:
> That what I thought - But how do I do either of the following.
>
> Create each of these 200+ hexes with a unique ID - so I can destoy or
> modify them.
>
> Or wipe the whole lot out so I can redraw it.
>
> I have been hitting the web sites and documentation but have not figured
> it out yet.
>

What's wrong with holding a reference to all the HexShape objects in a
Python list or some other data structure?