[python@lee-morgan.net] Re: [wxPython] OGL exhausting GDI heap (Win32)

Aha. Its not adding/removing shapes at all. The GDI heap memory leak is caused
by a simple repaint of the window.

This can be reproduced most easily by using the stress tool that comes with
MSVC6. (Or just repeatedly call Refresh())

If you run the OGL demo prog from the wxpython demos and the stress tool and hit
ctrl-insert to cause a refresh of the screen the GDI memory slowly leaks away.

This happens alot faster with my app as I've got 100's of bitmapshapes.

So, would this be a problem in OGL's bitmapshape repaint or elsewhere???

Raul Cota <cota@ucalgary.ca> writes:

Right now I use OGL to connect unit operations (shapes) and when ever I
load a new case, I delete all the shapes from it, and then add the new
ones, and I still haven't had those problems (maybe I haven't tested
enough though).

I just ran my application and opened and closed cases a lot of times, to
see if I get that problem and I didn't (but I don't really know what
"many" menas for you).

#This is how I delete shapes (code for deleting lines not included).
        canvas = self.pfd
        dc = wxClientDC(canvas)
        canvas.PrepareDC(dc)
        redraw = false
#imgsUO is a member dict with an instance of all the shapes
        for i in canvas.imgsUO.keys():
            shape = canvas.imgsUO[i]
            canvas.RemoveShape(shape)
            del canvas.imgsUO[i]
            shape.Destroy()
        canvas.Refresh()

The only difference I see is that I don't use Erase (sorry, I haven't
done reference count yet)

You're right, Erase is superflous - left over from when I wanted to delete a
shape without causing a whole diagram refresh.

Yes, I dont get the problem if I delete all, which I do (similarly to your code)

        for shape in self.theDiagram.GetShapeList():
            if shape.GetId() != self.backgroundShapeID:
                self.theDiagram.RemoveShape(shape)
                shape.SetCanvas(None)
                shape.Destroy()
# print 'bitmap refcount',sys.getrefcount(self.featureTemplates[0].wxbitmap)
        self.featureTemplates =

but I do when deleting one, which perhaps suggests an internal issue when
removing one shape and calling refresh. Or perhaps <canvas>.RemoveShape()
actually does more than call <canvas>.<diagram>.RemoveShape(). Hmm, more testing
needed to find out what I'm doing wrong.

Given I have to refresh the whole diagram on a delete its probably only a
marginal cost to deleteAll and recreate them.

Thanks for the help.

···

Raul

I use Win NT, wxPython 3.2.1

python@lee-morgan.net wrote:
>
> Hi,
>
> I'm bending OGL's purpose a little and trying to use it as a very simple 2D mapping
> component (if anyone knows a better solution I'd love to hear it!).
>
> So, I've got many small bitmaps arranged on a background. When I delete them I
> eventually exhaust the GDI heap.
>
> my delete involves
>
> dc = wxClientDC(self)
> shape.Erase(dc)
> self.theDiagram.RemoveShape(shape)
> shape.SetCanvas(None)
> shape.Destroy()
> self.Refresh()
>
> shape has a getrefcount() of 4, which is odd. 1 for getrefcount, 1 in the delete
> function but the others I can't account for.
>
> My first thought was the shapes are being kept alive, but it appears that
> deleting exhausts the heap much quicker than adding alot of bitmap shapes.
>
> So perhaps its the refresh thats causing some sort of duplication??
>
> Has anyone got any ideas or experience with this?
>
> Cheers
>
> --
> wxPython
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
wxPython

Aha. Its not adding/removing shapes at all. The GDI heap memory leak is

caused

by a simple repaint of the window.

This can be reproduced most easily by using the stress tool that comes

with

MSVC6. (Or just repeatedly call Refresh())

If you run the OGL demo prog from the wxpython demos and the stress tool

and hit

ctrl-insert to cause a refresh of the screen the GDI memory slowly leaks

away.

This happens alot faster with my app as I've got 100's of bitmapshapes.

So, would this be a problem in OGL's bitmapshape repaint or elsewhere???

Is it just when a bitmap shape is used?

···

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

"Robin Dunn" <robin@alldunn.com> writes:

>
> Aha. Its not adding/removing shapes at all. The GDI heap memory leak is
caused
> by a simple repaint of the window.
>
> This can be reproduced most easily by using the stress tool that comes
with
> MSVC6. (Or just repeatedly call Refresh())
>
> If you run the OGL demo prog from the wxpython demos and the stress tool
and hit
> ctrl-insert to cause a refresh of the screen the GDI memory slowly leaks
away.
>
> This happens alot faster with my app as I've got 100's of bitmapshapes.
>
> So, would this be a problem in OGL's bitmapshape repaint or elsewhere???

Is it just when a bitmap shape is used?

No. I had a quick look at OGL code last night and couldn't see anything obvious
in bitmapshape(although I have no wxWindow C experience!). After removing the
bitmap in the demo it still occurs.

Infact it occurs when adding one shape - the canvas without any shapes doesn't
have the problem.

So, it could as easliy be a font/pen/brush/etc as a bitmap alloc. And presumably
(guessing) only a bitmap alloc if related to a blit.

···

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
wxPython

Hi Robin,

Did you have any ideas on where this problem is? Are there any other tests I
could do that spring to mind?

Cheers

python@lee-morgan.net writes:

···

"Robin Dunn" <robin@alldunn.com> writes:

> >
> > Aha. Its not adding/removing shapes at all. The GDI heap memory leak is
> caused
> > by a simple repaint of the window.
> >
> > This can be reproduced most easily by using the stress tool that comes
> with
> > MSVC6. (Or just repeatedly call Refresh())
> >
> > If you run the OGL demo prog from the wxpython demos and the stress tool
> and hit
> > ctrl-insert to cause a refresh of the screen the GDI memory slowly leaks
> away.
> >
> > This happens alot faster with my app as I've got 100's of bitmapshapes.
> >
> > So, would this be a problem in OGL's bitmapshape repaint or elsewhere???
>
> Is it just when a bitmap shape is used?

No. I had a quick look at OGL code last night and couldn't see anything obvious
in bitmapshape(although I have no wxWindow C experience!). After removing the
bitmap in the demo it still occurs.

Infact it occurs when adding one shape - the canvas without any shapes doesn't
have the problem.

So, it could as easliy be a font/pen/brush/etc as a bitmap alloc. And presumably
(guessing) only a bitmap alloc if related to a blit.

>
> --
> Robin Dunn
> Software Craftsman
> robin@AllDunn.com Java give you jitters?
> http://wxPython.org Relax with wxPython!
>
>
>
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users
>

--
wxPython

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
wxPython

Did you have any ideas on where this problem is? Are there any other tests

I

could do that spring to mind?

Are you using 2.3.1? If so it looks like it's been fixed already. I can't
duplicate it in my current wxPython workspace, and there were some known GDI
issues in 2.3.1.

···

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

"Robin Dunn" <robin@alldunn.com> writes:

>
> Did you have any ideas on where this problem is? Are there any other tests
I
> could do that spring to mind?
>

Are you using 2.3.1? If so it looks like it's been fixed already. I can't

Yep, just tried 2.3.2b7 and the problems gone. An easy fix - cheers!

···

duplicate it in my current wxPython workspace, and there were some known GDI
issues in 2.3.1.

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

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
wxPython