×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Apr 2012
    Posts
    24

    efficiency of dynamically created elements

    Hi! Would just like to ask how efficient dynamically created elements are. I am trying to create a game framework that simply calls elements/components into a main screen. Here are some details of my question:

    - Is dynamically creating a component in a page as quick to load as statically created components(no perceivable difference or latency)? Will all the available components be loaded in RAM?

    - Does dynamically created component consume more resources? Is it alright if I would create a game level framework for which I create dynamic components or better create levels with all the static components (background etc..) statically coded?

    I am worried of hogging the mobile phone's resources and I cannot do testing yet because my test phone arrives two weeks from now, I would just like to avert the disaster that may occur (restructure the application) while I am beating the deadline for our capstone . Thanks in advance!

  2. #2
    Nokia Developer Expert
    Join Date
    Oct 2007
    Posts
    441

    Re: efficiency of dynamically created elements

    Hi

    At least your QML is not executed from file but loaded to memory first --- so i don't think there is much difference in static and dynamic component creation. Check "Loader" QML element. Using that you can unload previously loaded QML file and safe memory. If you use CreateComponent approach , you shall release created object by object.delete -- (javascript call) -- in most cases that object is created in a JScript function and reference on it is lost after the function exit -- so you will have to solve that problem : how to keep reference on created object to delete it later. There are a lot of tricks as for example implementing in the object a signal slot to handle self - destruction.... etc.

    Use of "Loader" QML element is much easier.

  3. #3
    Registered User
    Join Date
    Apr 2012
    Posts
    24

    Re: efficiency of dynamically created elements

    Thanks for that information. What if I use object.destroy(), does it also free resources from the memory?
    Last edited by pizarro84; 2012-04-16 at 16:59.

  4. #4
    Nokia Developer Expert
    Join Date
    Oct 2007
    Posts
    441

    Re: efficiency of dynamically created elements

    Hi

    object.destroy() will release allocated memory for this object. Here is code snippet from some working project -- it demonstrates dynamically created one-shot event handler .. it destructs itself after message has been handled:

    Code:
    ///CatalogEventHandlers.qml
    Connections {
        id: eventhandler
        ignoreUnknownSignals: true
    ................
        onMessageReceived: {
            // after processing it is not needed anymore
            //TODO: add some application specific code to handle the message
            eventhandler.destroy();
        }
    ................
    }
    
    ///Some different file
    function requestAsync(functRequest, onSucces, onFailure){
        var component = Qt.createComponent(Qt.resolvedUrl("CatalogEventHandlers.qml"));
        if(component.status === Component.Ready) {
            var replyObj = functRequest();
            // there is 'null' for no object parent
            var handler = component.createObject(null);
            handler.target = replyObj;
            handler.setCallbacks(onSucces, onFailure);
        }else{
            console.log("not ready --->" + component.status);
        }
    }

  5. #5
    Registered User
    Join Date
    Apr 2012
    Posts
    24

    Re: efficiency of dynamically created elements

    Oh I see, thanks for the code! By the way, is a 4MB just right for a two-dimensional mobile game? (resources and code, haven't compiled it tho, not yet finished and having troubles with the test compile)

  6. #6
    Nokia Developer Expert
    Join Date
    Oct 2007
    Posts
    441

    Re: efficiency of dynamically created elements

    Hi

    This pure QML game runs smoothly on N8-00 (32 M). Just for testing purposes , try it on device with 4M. The application creates QML elements dynamically. I've never analyzed memory consumption for this and i am wandering if 4 M will be enough --- Please let me know your finding.
    Last edited by izinin; 2012-04-23 at 06:31.

Similar Threads

  1. Using dynamically created TabButtons causes a program to crash.
    By marknotgeorge in forum [Archived] Qt Quick
    Replies: 3
    Last Post: 2012-01-21, 18:04
  2. Replies: 2
    Last Post: 2010-10-10, 06:10
  3. Dynamically created threads
    By kunlamp in forum Symbian
    Replies: 1
    Last Post: 2009-11-10, 08:56
  4. Replies: 6
    Last Post: 2009-10-27, 10:56
  5. RMS efficiency
    By sommeralex in forum Mobile Java General
    Replies: 2
    Last Post: 2007-02-19, 22:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •