Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 1,622
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido
Accepted Solution

Do I have to free memory when using createRootObject() ?

If I load an qml page and display it do I have to free it when the page is closed?

 

For example

 

        QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
        if (qml) {
            _page = qml->createRootObject<Page>();
        }


main.qml

 

Page

{

   Container

   {

        // some controls

   }

 

}

 

 

So when I close the page do I have to free _page or _page belongs the app and it is free when the app closes?

 

 

 

Developer
Posts: 1,159
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Do I have to free memory when using createRootObject() ?

That depends. If you don't care if the page hangs around until the app closes, then you can just rely on the parent(this) to destroy the page when the parent object is destroyed. If you want to create and destroy pages at will though, you should destroy the page when you are done with it. In C++ you can do it with delete() or deleteLater(), and in QML/JavaScript you can use page.destroy()

 

The important thing is that if you create a page at runtime, it must be destroyed again, either explicitly, or by assigning a parent object to own it.


smiley wrote:

If I load an qml page and display it do I have to free it when the page is closed?

 

For example

 

        QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
        if (qml) {
            _page = qml->createRootObject<Page>();
        }


main.qml

 

Page

{

   Container

   {

        // some controls

   }

 

}

 

 

So when I close the page do I have to free _page or _page belongs the app and it is free when the app closes?

 

 

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 16,987
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Do I have to free memory when using createRootObject() ?

also note, that, for whatever reason, signals are not disconnected when qml components are deleted.
i had this issue a few times when i connected signals in dynamically created pages.

my usual approach is now to delete pages in the onPopTransitionEnded/onNavigateToTransitionEnded slots of the navigation pane.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 1,622
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Do I have to free memory when using createRootObject() ?

thanks guys.