QtQuick, multiple string concatenation and embedded devices



  • I've written an application for Windows XP/Vista/7 and Windows CE 6.0 (ARM) with Qt 4.7.3
    using QtQuick for the configurable UI and with some extra QML elements written in C++.
    The desktop version had no problems, but the embedded version had a very weird
    memory leak.

    It happened in javascript code (in the QML side of the application)
    when assigning a concatenated string expression to a string property
    of a custom QML element written in C++.

    I.e.

    myObject.myStringproperty = "aaaa" + anotherObject.anotherStringProperty + "bbbb"

    produced a memory leak, while

    myObject.myStringproperty = ["aaaa", anotherObject.anotherStringProperty, "bbbb"].join()

    works without problems.

    My guess is that the temporary strings allocated by the sequence of consecutive concatenations
    are not deallocated properly or cause some weird fragmentation in the heap, while the join()
    does string concatenation precalculating the resulting string size (i.e. no temporary strings)
    or does deallocation of temporary strings in a different way.

    Does somebody else noticed the same problem on other Windows CE devices or on other platforms ?



  • Does it leak indefinitely or does the garbage collector eventually reclaim it? If not then I would file a bug for this if I were you.



  • @ZapB: on my Windows CE 6 device it seems it leaks indefinitely.

    I’ve asked here in the forum because I wanted to check if somebody else had problems like this.

    I’m still trying to understand what’s exactly happening because it may be caused by a circular chain of dependencies or by something wrong in my customized windows CE image.

    When the property in my custom QML Element is modified there is data transmitted to a remote device (using a separate thread to decouple the I/O operations from the main thread) and when the answer from the remote device is received the same element emits some events on the qml side.

    At first I looked into my C++ code thinking the problem was there, then looking at the javascript code written by the developer responsible of the UI customization I noticed the leaks happened when there were lots of string concatenations before setting the custom property, using a simple string copy (i.e. myProperty = “a single string”) there were no problems and when i tried using join() (to check if the leaking got better or worse) the leaks vanished.
    On Windows 7 it seems there are no problems, but there memory management is different.

    Before filing a bug report I want to be sure it isn’t something i did with my custom C++ QML elements and if there is a way to easily replicate it with a simple example on other device/OS.



  • I understand. Probably the best bet is to try to make a very minimal example (circa 200 lines of code) that reproduces the problem then post it here. Then we can try it too. It sounds like you have already investigated to quite an extent though. Still such examples are very useful to attach to the bug reports to help the devs resolve them more quickly.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.