Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Permanent memory usage increase
Forum Updated to NodeBB v4.3 + New Features

Permanent memory usage increase

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dpetri
    wrote on last edited by
    #1

    we have a multi-thread c++ qt (4.8.1) application on an embedded arm linux platform with many qgraphicsitem descendants. When calling their update() method, mtrace shows incremental memory usage, some 16-18 bytes on each update. Watching the application's virtual memory usage (VSZ columnt with ps, or top commands), it is also incrementing constantly. If we start the application within valgrind --tool=memcheck, and the application terminates normally, we don't see "definitely lost" blocks.

    If we comment out the update() calls, mtrace does not show any more unfreed areas.

    Is it possible that there are "still reachable" and constantly growing memory blocks, reallocated areas, STL vectors, etc., within Qt? If yes, how can we clear them periodically?

    The program structure is as follows:

    @int main( int argc, char* argv[] ) {
    // new thread creations, initializations, qt object creations
    ...
    mtrace();
    while ( runEnabled ) {
    // this is where new events arrive, and the graphics is updated
    ...
    }
    muntrace();
    // cleanups, desctructions
    ...
    }@

    So mtrace monitors only the active part, which should run for months in our embedded environment.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mehrdadsilver
      wrote on last edited by
      #2

      Do you build (with new) objects in PaintEvent of qgaphicsItem such as QPainter object? if yes you should control them .

      Mehrdad Abdolghafari, Be silver

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dpetri
        wrote on last edited by
        #3

        Thanks for the reply. No, there is no dynamic allocation neither in the paint() method nor any subsequent methods. One of the paint() methods look like:

        @void Entity::paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget ) {
        if ( getCurrentFont( ) != NULL ) {
        painter->setFont( *getCurrentFont( ) );
        }
        else {
        painter->setFont( *Document::getDefaultFont( ) );
        }

            QPen pen = QPen( );
            pen.setColor( *getFgColor( ) );
            setLineStyleAndWidth( &pen );
            painter->setPen( pen );
            painter->setBrush( currentBrush );
        
            if ( staticPath != NULL ) {
              painter->drawPath( *staticPath );
            }
        
            if ( currentPath != NULL ) {
              pen.setStyle( Qt::SolidLine );
              if ( drawStateBold ) {
                pen.setWidth( getLineWidth( ) * 2 );
                painter->setPen( pen );
              }
        
              painter->drawPath( *currentPath );
            }
        
            paintHandle( painter );
        
            if ( drawQuestionmark ) {
              // A kérdőjelet forgatástól függetlenül kell rajzolni
              QFont fnt = painter->font( );
              fnt.setPixelSize( ( boundingRect( ).height( ) - 2.5 * mm2px ) * originalScale.y( ) );
              painter->setFont( fnt );
        
              QTransform save = painter->transform( );
              painter->setTransform( QTransform( ) );
              painter->drawText( save.mapRect( boundingRect( ) ), Qt::AlignCenter, "?" );
              painter->setTransform( save );
            }
          }@
        

        The boundingRect() methods also do not allocate memory from the heap:

        @QRectF TextBox::boundingRect( ) const {
        return QRectF( -0.5 * getLineWidth( ),
        -0.5 * getLineWidth( ),
        width + getLineWidth( ) * 0.5,
        height + getLineWidth( ) * 0.5 );
        }@

        Other methods called from these two are also already checked.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved