Permanent memory usage increase



  • 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.



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



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.