Hrundik wrote:
Hi folks!
Is there a way to reduce wxPython memory consuption?
import wx eats about 14 MBs of RAM, so even the smallest app will eat about 16-18 MBs, which is a lot for a small app.
I'm a bit new to this, but I was thinking the same thing... so i tried instead of 'import wx' using 'from wxPython.wx import wxFrame' etc etc
On my Linux 2.4.28 box with Python 2.3 and wxPython 2.5.3.1 importing the whole wx seems to gobble 9.7mbs - when I just imoprted the bits I needed (wxFrame, wxMenuBar, wxMenu, wxApp... [and a couple of others]) for a small notepad tutorial i downloaded it decreased to 9.4mbs - not great.
···
Or this problem can't be solved?..
On my Linux 2.4.28 box with Python 2.3 and wxPython 2.5.3.1 importing the whole wx seems to gobble 9.7mbs
I would suggest studying up on operating system memory usage. Things
don't work in the simple way you think they are
In particular you'll want to understand shared libraries, memory mapping,
the ELF format, swapping, copy on write and several other concepts. I
assume you are using the output of top to try and work this out. There has
been much debate about whether top should even show the memory columns since
they are very easy to misinterpret, as well as there being statistical issues
(eg who do you charge shared read-only or cow pages to)
Roger
memory usage and tracking, I think that Hrundik's point still stands:
wxPython applications use a lot of memory -- even to startup the
simplest of apps. I would not take this as a cut against wxPython, but
rather as an area we can improve in.
One of the simplest issues is that wxPython includes a lot of functionality.
It could be split into hundreds of dlls. But there isn't that much milage
in doing so. (Or more accurately, feel free to do the work yourself).
Shared libraries are demand paged, so you only use as much memory as your
code actually uses.
Another thing I've noticed is how many DLLs wx apps load.
I don't know how you worked this stuff out, but I use Process
Explorer from sysinternals.com. This is what it lists for
notepad:
Name Description Company Name Version
acgenral.dll Windows Compatibility DLL Microsoft Corporation 5.01.2600.2180
advapi32.dll Advanced Windows 32 Base API Microsoft Corporation 5.01.2600.2180
comctl32.dll User Experience Controls Library Microsoft Corporation 6.00.2900.2180
comdlg32.dll Common Dialogs DLL Microsoft Corporation 6.00.2900.2180
ctype.nls
gdi32.dll GDI Client DLL Microsoft Corporation 5.01.2600.2180
idle.dll idle Yahoo! Inc. 1.00.0000.0002
itchhk.dll iTouch Hook Library Logitech Inc. 1.00.0000.0000
KbdHook.dll Keyboard Hook Library Logitech Inc. 2.22.0289.0000
kernel32.dll Windows NT BASE API Client DLL Microsoft Corporation 5.01.2600.2180
LGMSGHK.DLL Logitech Message Hook Library Logitech Inc. 1.01.0000.0000
locale.nls
msacm32.dll Microsoft ACM Audio Filter Microsoft Corporation 5.01.2600.2180
msvcr71.dll Microsoft® C Runtime Library Microsoft Corporation 7.10.3052.0004
msvcrt.dll Windows NT CRT DLL Microsoft Corporation 7.00.2600.2180
notepad.exe Notepad Microsoft Corporation 5.01.2600.2180
ntdll.dll NT Layer DLL Microsoft Corporation 5.01.2600.2180
ole32.dll Microsoft OLE for Windows Microsoft Corporation 5.01.2600.2180
oleaut32.dll Microsoft Corporation 5.01.2600.2180
rpcrt4.dll Remote Procedure Call Runtime Microsoft Corporation 5.01.2600.2180
shell32.dll Windows Shell Common Dll Microsoft Corporation 6.00.2900.2180
shimeng.dll Shim Engine DLL Microsoft Corporation 5.01.2600.2180
shlwapi.dll Shell Light-weight Utility Library Microsoft Corporation 6.00.2900.2180
sortkey.nls
sorttbls.nls
unicode.nls
user32.dll Windows XP USER API Client DLL Microsoft Corporation 5.01.2600.2180
userenv.dll Userenv Microsoft Corporation 5.01.2600.2180
uxtheme.dll Microsoft UxTheme Library Microsoft Corporation 6.00.2900.2180
version.dll Version Checking and File Installation Libraries Microsoft Corporation 5.01.2600.2180
winmm.dll MCI API DLL Microsoft Corporation 5.01.2600.2180
winspool.drv Windows Spooler Driver Microsoft Corporation 5.01.2600.2180
I'm sure that my verySimpleApp does not need everything here.
Particularly html and the socket stuff.
I didn't see any HTML stuff listed in your DLLs. I do see winsock
but that is because wxPython links against winsock. The Windows
dynamic linking scheme is some what brain dead so you'll get that.
I believe there is a way to reduce the memory footprint of wx apps,
Which is? Splitting into smaller files will make apps that do nothing
use less, but the moment you do a normal amount of stuff with an
application you'll suck them all back in and memory usage will be
worse with lots of smaller shared libraries.
To be honest, if you care about the difference between 8MB and 12MB
then I would recommend writing your applications in C using MFC (not
C++). Or alternatively prototype them in wxPython and rewrite in
C.
Roger