I am building an application which utilizes several distinct QML UI pages that are loaded from C++ code. Now it seems that even if I manage to open the pages relatively easily, the solution I have built causes the application to crash in mobile device (N8) after several (tens of) page loads.

It seems that bigger the QML page content, the faster the app crashes. Thus I suspect that my page loading leaks resources.

Here is the page loading code. Any idea what is wrong?

    In header:
    QGraphicsScene *scene;
    QGraphicsView *view;
    QDeclarativeEngine *engine;
    QDeclarativeContext *context;
    QDeclarativeComponent *component;
    QDeclarativeItem *item;
    QDesktopWidget *myScreen;
    QRect ScreenDim;

QmlCppMediator::QmlCppMediator(QObject *parent) :
    scene = new QGraphicsScene;
    view = new QGraphicsView(scene);
    engine = new QDeclarativeEngine();
    context = engine->rootContext();

Q_INVOKABLE void QmlCppMediator::changeQMLSource(QString page) {

    if (component){
        delete component;

    ScreenDim = myScreen->screenGeometry();
    int width = ScreenDim.width();
    int height = ScreenDim.height();

    scene->setSceneRect (0,0,width,height);

    component = new QDeclarativeComponent (engine, QUrl::fromLocalFile(page));
    item = qobject_cast<QDeclarativeItem *>(component->create());

br, _perza