[wxPython] Memory leak with OnIdle ?

I have a memory leak problem with a program that uses the OnIdle function. I
have written a small test program that shows the problem. I am using Windows
98 and Python 2.0. I check the amount of free memory with "Windows 95 Memory
Monitor".

from wxPython.wx import *
ID_START = 101
ID_STOP = 102

class TestDlg(wxDialog):
    def __init__(self, parent):
        wxDialog.__init__(self, parent, -1, "Testing in progress")
        self.stop = wxButton(self, ID_STOP, "Stop",wxPoint(50, 50))
        self.stop.SetDefault()
        self.Finished = 0
        self.Stop = 0
        EVT_BUTTON(self, ID_STOP, self.OnStop)
        EVT_IDLE(self, self.OnIdle)

    def OnIdle(self, event):
        if not self.Finished:
            if self.Stop:
                self.Finished = 1
                self.Close(true)
            else:
                event.RequestMore()

    def OnStop(self, event):
        self.Stop = 1

class MainFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                         wxDefaultPosition)

        self.SetBackgroundColour(wxColor(250,240,220))

        b = wxButton(self, ID_START, "Start", wxPoint(300, 400))
        EVT_BUTTON(self, ID_START, self.OnClick)

    def OnClick(self, event):
        dlg = TestDlg(self)
        dlg.Show(true)
        dlg.ShowModal()
        dlg.Destroy()

class MyApp(wxApp):
    def OnInit(self):
        frame = MainFrame(NULL, -1, "Test")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()

As soon as I click on the "Start" button, the free memory is decreasing
endless. When I click on the "Stop" button, the free memory remains stable.

Any idea ?

Thanks for your help

Jean-Claude Repetto
Vallauris, France

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Getting rid of the
         dlg.Show(true) # this is unnecessary (and possibly wasteful---but
of
#[a very little] time, not memory...
is the first thing I tried... no change. [I mention this though because it
IS unnecessary.]

But from my memory of how idle events are processed, I next tried removing
the
event.RequestMore () {this method actually didn't exist when I was looking
at idle processing a year or so ago, so that was a very natural thing to try
for me!}. This appears to plug your memory leak.
The reason the event.RequestMore () appears to be unnecessary can be found
in the documentation for wxIdleEvent::RequestMore:
"
void RequestMore(bool needMore = TRUE)

Tells wxWindows that more processing is required. This function can be
called by an OnIdle handler for a window or window event handler to indicate
that wxApp::OnIdle should forward the OnIdle event once more to the
application windows. If no window calls this function during OnIdle, then
the application will remain in a passive event loop (not calling OnIdle)
until a new event is posted to the application by the windowing system.
"

The RequestMore is not necessary because of the last clause of the last
sentence, and simply allocates memory for more and more wxIdleEvent
structures, etc.... At least, that's the way it seems to me!

Have a brilliant New Year!

Cheerio, Chris

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@uq.net.au> Phone:(07) 3870 5639
Brisbane, Australia Mobile:(0400) 833 700
-------------------------------------------------------------------------
-o0= Strange but true... (?!) =0o-
The combination "ough" can be pronounced in nine different ways. The
following sentence contains them all: "A rough-coated, dough-faced,
thoughtful ploughman strode through the streets of Scarborough; after
falling into a slough, he coughed and hiccoughed."

-----Original Message-----
From: wxpython-users-admin@lists.sourceforge.net
[mailto:wxpython-users-admin@lists.sourceforge.net]On Behalf Of
Jean-Claude REPETTO
Sent: Wednesday, 27 December 2000 9:25 PM
To: wxpython-users@lists.sourceforge.net
Subject: [wxPython] Memory leak with OnIdle ?

I have a memory leak problem with a program that uses the OnIdle
function. I
have written a small test program that shows the problem. I am
using Windows
98 and Python 2.0. I check the amount of free memory with
"Windows 95 Memory
Monitor".

from wxPython.wx import *
ID_START = 101
ID_STOP = 102

class TestDlg(wxDialog):
    def __init__(self, parent):
        wxDialog.__init__(self, parent, -1, "Testing in progress")
        self.stop = wxButton(self, ID_STOP, "Stop",wxPoint(50, 50))
        self.stop.SetDefault()
        self.Finished = 0
        self.Stop = 0
        EVT_BUTTON(self, ID_STOP, self.OnStop)
        EVT_IDLE(self, self.OnIdle)

    def OnIdle(self, event):
        if not self.Finished:
            if self.Stop:
                self.Finished = 1
                self.Close(true)
            else:
                event.RequestMore()

    def OnStop(self, event):
        self.Stop = 1

class MainFrame(wxFrame):
    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title,
                         wxDefaultPosition)

        self.SetBackgroundColour(wxColor(250,240,220))

        b = wxButton(self, ID_START, "Start", wxPoint(300, 400))
        EVT_BUTTON(self, ID_START, self.OnClick)

    def OnClick(self, event):
        dlg = TestDlg(self)
        dlg.Show(true)
        dlg.ShowModal()
        dlg.Destroy()

class MyApp(wxApp):
    def OnInit(self):
        frame = MainFrame(NULL, -1, "Test")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()

As soon as I click on the "Start" button, the free memory is decreasing
endless. When I click on the "Stop" button, the free memory
remains stable.

Any idea ?

Thanks for your help

Jean-Claude Repetto
Vallauris, France

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

I have a memory leak problem with a program that uses the OnIdle
function. I
have written a small test program that shows the problem. I am
using Windows
98 and Python 2.0. I check the amount of free memory with
"Windows 95 Memory
Monitor".

After patching libpy.c from wxPython sources this does not occur anymore

SWIGSTATICRUNTIME(char *)
SWIG_GetPtrObj(PyObject *obj, void **ptr, char *type) {
  PyObject *sobj = obj;
  char *str;
  if (!PyString_Check(obj)) {
      if (!PyInstance_Check(obj) || !(sobj =
PyObject_GetAttrString(obj,"this")))
          return "";
// PyObject_GetAttrString incerases sobj refcout !
      Py_DECREF(sobj);
  }
  str = PyString_AsString(sobj);
  return SWIG_GetPtr(str,ptr,type);
}

mak

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Hi Chris,

Thanks for your answer.

But from my memory of how idle events are processed, I next tried removing
the
event.RequestMore () {this method actually didn't exist when I was looking
at idle processing a year or so ago, so that was a very natural thing to

try

for me!}. This appears to plug your memory leak.

Unfortunately, it works for this test program, but not for my real program.
The real program is driving an external equipment through the serial port,
and it has to monitor the equipment, to wait for an event (for example, the
external equipment has finished its task).
If I remove the RequestMore() call, the monitoring only occurs when I move
the mouse or type a key. That is not what I want, the monitoring must be
continuous.

I wish you a happy new year !

Jean-Claude

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

has anyone had experience using both wxPython and PyGTK?? I'm just wondering what some of the strengths and weaknesses of each are relative to one another...

speed?
resources?
bugginess?
ease of programming?
multiplatform (obviously wxPython wins this one).

basically, I'm considering picking up some PyGTK in addition to what I've learned of wxPython and am wondering if it's worth the effort..

thanks.

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

How annoying for you...

Well, all I can suggest is that idle processing may not be the way to go.
Perhaps you might try multi-threading (there's an example in the demo),
creating a new thread for waiting for and processing the serial I/O (with
the caveat that said thread will have to communicate with the main thread
when it wants to update the GUI; see the demo).

Cheerio, Chris

···

-------------------------------------------------------------------------
Chris Fama <mailto:Chris.Fama@uq.net.au> Phone:(07) 3870 5639
Brisbane, Australia Mobile:(0400) 833 700
-------------------------------------------------------------------------
Her shadow fell upon his breast, and charmed / A tumult to his heart,
and a new life / Into his eyes. Ah, miserable strife, / But for her
comforting! unhappy sight, / But meeting her blue orbs! Who, who can
write / Of these first minutes? The unchariest muse / To embracements
warm as theirs makes coy excuse.
                   - Keats, from "Endymion -- A Poetic Romance", book I

-----Original Message-----
From: wxpython-users-admin@lists.sourceforge.net
[mailto:wxpython-users-admin@lists.sourceforge.net]On Behalf Of
Jean-Claude REPETTO
Sent: Friday, 29 December 2000 7:26 PM
To: wxpython-users@lists.sourceforge.net
Subject: Re: [wxPython] Memory leak with OnIdle ?

Hi Chris,

Thanks for your answer.

> But from my memory of how idle events are processed, I next
tried removing
> the
> event.RequestMore () {this method actually didn't exist when I
was looking
> at idle processing a year or so ago, so that was a very natural thing to
try
> for me!}. This appears to plug your memory leak.

Unfortunately, it works for this test program, but not for my
real program.
The real program is driving an external equipment through the serial port,
and it has to monitor the equipment, to wait for an event (for
example, the
external equipment has finished its task).
If I remove the RequestMore() call, the monitoring only occurs when I move
the mouse or type a key. That is not what I want, the monitoring must be
continuous.

I wish you a happy new year !

Jean-Claude

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

A few days ago, Grzegorz Makarewicz proposed a patch for libpy.c to solve a
memory leak problem (see my messages on the mailing list).

SWIGSTATICRUNTIME(char *)
SWIG_GetPtrObj(PyObject *obj, void **ptr, char *type) {
  PyObject *sobj = obj;
  char *str;
  if (!PyString_Check(obj)) {
      if (!PyInstance_Check(obj) || !(sobj =
PyObject_GetAttrString(obj,"this")))
          return "";
// PyObject_GetAttrString incerases sobj refcout !
      Py_DECREF(sobj);
  }
  str = PyString_AsString(sobj);
  return SWIG_GetPtr(str,ptr,type);
}

I'd like to try it, but I've never built wxPython, and I need some help.
I am using Microsoft Visual Studio 6 SP4, but never the command line tools.

I downloaded the wxWindows and wxPython source code, and I installed them in
the c:\wx2 directory

First I copied setup0.h to setup.h and I edited setup.h .
Then I typed the commands :
set WXWIN=c:\wx2
nmake -f makefile.vc dll pch USE_GLCANVAS=1 FINAL=hybrid
Result : Invalid command or file name

So I added "C:\Program Files\Microsoft Visual Studio\VC98\BIN" to the path.
Result of the nmake command: ..\makevc.env(9) : fatal error U1052: file
'ntwin32.mak' not found

So I added the following line to the environment :
INCLUDE="C:\Program Files\Microsoft Visual Studio\VC98\include"
Result of the nmake command:
dummydll.cpp
C:\WX2\include\wx/defs.h(223) : fatal error C1083: Cannot open include file:
'st
ddef.h': No such file or directory
Since this file is in "C:\Program Files\Microsoft Visual
Studio\VC98\include", I don't understand.

Have I forgotten something ?

Thanks for your help.

Jean-Claude

···

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

I'd like to try it, but I've never built wxPython, and I need some help.
I am using Microsoft Visual Studio 6 SP4, but never the command line

tools.

When Visual Studio was installed, it probably created a file named something
like VCVARS.BAT, (on win 9x anyway.) Try executing that to get the
environment setup correctly.

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

>
>
> I'd like to try it, but I've never built wxPython, and I need some help.
> I am using Microsoft Visual Studio 6 SP4, but never the command line
tools.
>

When Visual Studio was installed, it probably created a file named

something

like VCVARS.BAT, (on win 9x anyway.) Try executing that to get the
environment setup correctly.

Thanks, I had launched VCVARS32.BAT, but I didn't notice that it was wrong.
I had changed my hard disk, and manually copied the files from the old disk
to the new. Unfortunately VCVARS32.BAT uses short MSDOS names,
and the short name for "Microsfot Visual Studio" had changed from MICROS~1
to MICROS~4 !

So I have successfully rebuilt wxWindows.

Now, I have problems to rebuild wxPython.

First, problem, with sglcanvas.cpp !

sglcanvas.cpp
contrib/glcanvas\msw\glcanvas.cpp(119) : error C2065: 'wxGLContext' :
undeclared identifier
contrib/glcanvas\msw\glcanvas.cpp(119) : error C2065: '_result' : undeclared
identifier
contrib/glcanvas\msw\glcanvas.cpp(119) : warning C4552: '*' : operator has
no effect; expected operator with side-effect
contrib/glcanvas\msw\glcanvas.cpp(121) : error C2065: 'wxGLCanvas' :
undeclared identifier
contrib/glcanvas\msw\glcanvas.cpp(121) : error C2065: '_arg1' : undeclared
identifier
contrib/glcanvas\msw\glcanvas.cpp(121) : warning C4552: '*' : operator has
no effect; expected operator with side-effect
contrib/glcanvas\msw\glcanvas.cpp(149) : error C2059: syntax error : ')'
contrib/glcanvas\msw\glcanvas.cpp(165) : error C2065: '_arg0' : undeclared
identifier
contrib/glcanvas\msw\glcanvas.cpp(165) : warning C4552: '*' : operator has
no effect; expected operator with side-effect
contrib/glcanvas\msw\glcanvas.cpp(181) : error C2541: delete : cannot delete
objects that are not pointers
contrib/glcanvas\msw\glcanvas.cpp(192) : warning C4552: '*' : operator has
no effect; expected operator with side-effect
contrib/glcanvas\msw\glcanvas.cpp(208) : error C2227: left of '->SetCurrent'
must point to class/struct/union
etc ...

So I edited setup.py to remove the glcanvas option, and I tried to rebuild.

Now, I have a library version problem :

LINK : fatal error LNK1181: cannot open input file "wx22_2.lib"
error: command '"C:\Program Files\Microsoft Visual
Studio\VC98\BIN\link.exe"' fa
iled with exit status 1181

The source files that I downloaded are :
wxMSW-2.2.1-setup.zip
wxWindows-2.2.1-vc.zip
wxPython-2.2.2.tar.gz

I have not found a 2.2 version of wxWindows on your site .

Thanks again for your help

Jean-Claude

···

----- Original Message -----
From: "Robin Dunn" <robin@alldunn.com>
To: <wxpython-users@lists.sourceforge.net>
Sent: Thursday, January 04, 2001 5:23 PM
Subject: Re: [wxPython] Newbie needs help to rebuild wxPython for Win32

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Hi,

Is wxPython 2.2.2 faster?
  it seem's that wxPython 2.2.2 is ?much? faster than 2.2.1
  (there was always a big diff between NT/ linux/sgi)
  could this - did you made changes/improvements ?

Mix or better not ?
may i use wxGTK-2.2.3 with wxPython-2.2.2?
  i tried this, and had some problems with scintilla,
  (demo run's, but after scrolling color went to gray
  it seems, there is an older version in
  wxGTK-2.2.2 : Scintilla1.25+
  wxGTK-2.2.3 : Scintilla-1.32

harald

···

--
Harald Schaeffler
BMW Group
Forschungs- und Ingenieurzentrum
Technologie Montage CA-Technik
TI-410

80788 Muenchen, Germany

Phone +49 89 38243531
Fax +49 89 38247140
Email: Harald.Schaeffler@bmw.de
                                        
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

Now, I have a library version problem :

LINK : fatal error LNK1181: cannot open input file "wx22_2.lib"
error: command '"C:\Program Files\Microsoft Visual
Studio\VC98\BIN\link.exe"' fa
iled with exit status 1181

The source files that I downloaded are :
wxMSW-2.2.1-setup.zip
wxWindows-2.2.1-vc.zip
wxPython-2.2.2.tar.gz

I have not found a 2.2 version of wxWindows on your site .

Try this one:

http://alldunn.com/wxPython/dist/others/wxMSW-2.2.2.zip

(I say "try" because I made this zip myself, and I probably didn't do it the
same way that Julian usually does.)

···

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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users