Results 1 to 3 of 3

Thread: Memory usage and QGraphicsView/Scene with QML component

  1. #1
    Join Date
    Mar 2012
    Location
    Germany
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Memory usage and QGraphicsView/Scene with QML component

    Hello,

    I unsure about where I should place the thread, so please move if it's in the wrong section.

    So, now to my problem.
    In my Qt program I have a stackedWidget and one page of the widget has a QGraphicsView in it.
    Before I enter the QGraphicsView I call a function which sets up my QGraphicsScene and loads a QML file:
    Qt Code:
    1. stackScene = new MyScene(); //inherits from QGraphicsScene
    2. engine = new QDeclarativeEngine();
    3. stackData = new MyData(); // contains several Vectors
    4. engine->rootContext()->setContextProperty("stackData", stackData);
    5. QDeclarativeComponent component(engine, QUrl(QString::fromUtf8("qrc:QML/stackSceneQML.qml")));
    6. //qDebug() << component.errors() << endl;
    7. object = qobject_cast<QGraphicsObject *>(component.create());
    8. stackScene->addItem(object);
    9.  
    10. // process to QGraphicsView
    To copy to clipboard, switch view to plain text mode 

    It works fine and all and I free all memory allocated with new from above when I leave the QGraphicsView:
    Qt Code:
    1. delete stackScene;
    2. stackScene = NULL;
    3. // delete engine; commented, because it gives me segmention fault...
    4. // delete object; well same as above
    5. delete stackData;
    6. stackData = NULL;
    To copy to clipboard, switch view to plain text mode 

    Now the behaviour I can not explain:
    The memory used is about 10 MB when I launch my program, entering the stackWidget with QGraphicsView
    adds a few kB - but leaving it doesn't remove even one kB instead I stays and adds more kB when I switch to it again.
    I stopped at 20MB...

    I hope someone may have a clue about what's going wrong here.

    It's really annoying.

  2. #2
    Join Date
    Mar 2012
    Location
    Germany
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Memory usage and QGraphicsView/Scene with QML component

    Here is the output of Valgrind:

    Qt Code:
    1. 32 bytes in 2 blocks are definitely lost in loss record 3,883 of 6,918
    2. in FcPatternCreate in /usr/lib/i386-linux-gnu/libfontconfig.so.1.4.4
    3. 1: malloc in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
    4. 2: FcPatternCreate in /usr/lib/i386-linux-gnu/libfontconfig.so.1.4.4
    5. 3: /home/jovin/source/myProgram-build-desktop-Qt_4_8_1_in_Pfad__System__Release/myProgram
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. 120 bytes in 1 blocks are definitely lost in loss record 6,202 of 6,918
    2. in QFontDatabase::load(QFontPrivate const*, int) in /build/buildd/qt4-x11-4.8.1/src/gui/text/qfontdatabase.cpp:1062
    3. 1: operator new(unsigned int) in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so
    4. 2: QFontDatabase::load(QFontPrivate const*, int) in /build/buildd/qt4-x11-4.8.1/src/gui/text/qfontdatabase.cpp:1062
    5. 3: /home/jovin/source/myProgram-build-desktop-Qt_4_8_1_in_Pfad__System__Release/myProgram
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2012
    Location
    Germany
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Memory usage and QGraphicsView/Scene with QML component

    Well, I more or less stopped the increase in memory. Now I create my stackScene only once and reuse it.

    Result: The memory usage is at 4MB when the program is first started.
    After switching to my QGraphicsScene it goes to 10MB and stays. Not matter how often I switch views. That's good.

    Now I would like to give all memory free that's used for the QGraphicsScene (means go back to 4MB after leaving it).
    How would I do that?

    My QGraphicsScene is set up as mentioned in the opening post.
    When deleting the stackScene and stackData pointer the memory doesn't really change.
    I guess it's the engine that's so memory hungry, but when trying to delete the engine it throws a segmention fault.

    I'm out of ideas.

Similar Threads

  1. Bad memory usage on QWebView I think
    By jiturra in forum Qt Programming
    Replies: 15
    Last Post: 21st January 2014, 20:35
  2. memory usage report
    By timmu in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2012, 14:42
  3. QStyles and it's memory usage
    By RSX in forum Qt Programming
    Replies: 0
    Last Post: 28th August 2009, 14:18
  4. CPU and Memory Usage
    By philwinder in forum Qt Programming
    Replies: 16
    Last Post: 17th May 2008, 22:25
  5. How to determine memory usage?
    By nopalot in forum General Programming
    Replies: 3
    Last Post: 11th February 2007, 19:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.