Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Using C++ Object to test QML Garbage Collection

    QML and Qt Quick
    2
    3
    1673
    Loading More Posts
    • 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.
    • W
      wade-J last edited by

      In my mobile game , I use QML. The performance is not stable and I am wondering whether the reason is garbage collection.
      Since I haven't found way to know when the QML does Garbage Collection, I used such way:

      I register a C++ type into QML , and create an instance in my JavaScript code. The C++ type is different in two points:

      (1)In constructor, QQmlEngine::setObjectOwnership(this,QQmlEngine::JavaScriptOwnership);
      (2)In destructor, emit gcSignal();

      So, eveytime QML does garbage collection, the instance will be destructed, and I can receive the gcSignal().

      Is this a useful way?
      Is there any other way to help?

      1 Reply Last reply Reply Quote 0
      • T
        t3685 last edited by

        That's one way of doing it. The problem for you would be to connect every object to make to a listeren of your gc signal.

        Before you go deeper into garbage collection, have you profiled the application with the qml profiler?

        1 Reply Last reply Reply Quote 0
        • W
          wade-J last edited by

          The phenomenon is that my game lags periodically. It is not obvious , but I can feel it. So I doubt it is of gc reason.

          I just use one object,I call it "ghost", to listen of the gc signal, and everytime gc happens, the ghost will destructed, and a new ghost will be created.

          If I thought it were right,I could receive the signal. And it works as I thought. What is weird is that I can not receive the signal if I add some irrelated code such as just add one line:var x = new Date(),when re-create the ghost. So confused.

          Yes , I profiled the application before.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post