Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Using C++ Object to test QML Garbage Collection
QtWS25 Last Chance

Using C++ Object to test QML Garbage Collection

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.9k Views
  • 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 Offline
    W Offline
    wade-J
    wrote on last edited by
    #1

    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
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      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
      0
      • W Offline
        W Offline
        wade-J
        wrote on last edited by
        #3

        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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved