[PyQt] Attempting to reduce the memory footprint of my PyQt5 application

Andreas Pakulat apaku at gmx.de
Thu Sep 8 00:13:49 BST 2016


Hi,

On Wed, Sep 7, 2016 at 11:57 PM, Xavion <xavion.0 at gmail.com> wrote:
> So, you're both saying that the following two lines are equivalent (from a
> memory footprint standpoint):
>
> from PyQt5.QtCore import QVariant
> from PyQt5 import QtCore
>
> In other words, in both cases, the whole of 'QtCore' will be imported
> (rather than just 'QVariant' in the first case).
>
> Florian: I think you're saying that I can reduce the memory usage by doing
> the following.  If so, can we get the UIC and RCC generators to behave this
> way?
>
> from PyQt5 import QtCore
> mVariant = QtCore.QVariant
> del QtCore

Lets clear up a misconception you seem to have: Neither Qt nor PyQt
have 'submodules' you can 'load'. Both consist of a set of shared
libraries, QtCore, QtXml, QtGui etc., where the PyQt modules just
contain the 'glue code' between C++ and Python. If you load 'part' of
one of those modules the whole of the shared library is loaded into
memory (at least with the common linkers used on the 3 major desktop
OS).

So wether you import QtCore or just QtCore.QVariant makes no
difference in terms of memory footprint of your application. AFAIK the
only option to reduce the memory needed to load QtCore (or other Qt
modules) is to strip stuff out of them when building. Qt allows to
disable certain parts and features that you don't need and I'd assume
PyQt adapts to that also only including stuff that Qt has support
built in for.

Andreas


More information about the PyQt mailing list