Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-64131

Read/Write array to INI settings collects garbage

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.6
    • Core: I/O
    • None

    Description

      1. Open settings file in INI format and write to it the filled QStringList with beginWriteArray()/endArray() functions. Write for example different 10 strings.
      2. Open INI file to read in third party text editor and watch all 10 strings written. Variable "size=10" will be written at the end of array. That's right.
      3. Open in code this array and read array to QStringList with beginReadArray()/endArray() functions.
      4. Remove some (for example 5) random lines from this QStringList.
      5. Write it again with same method as used in step 1. Write only 5 rest lines.
      6. Open INI again in text editor - you will see 10 (not 5) lines in array. First 5 will  correspond to lines written in step 5. Next 5 will be "tail" of 10 lines written in step 1. And you will see "size=5" at the end of array.

      That means - if you will write bigger and bigger arrays - then QSettings engine will collect and carry garbage in INI file. Once you wrote 1000 items - next time INI file will keep all 1000 items even if only 1 item will be used in all next job. And QSettings will read and write 1000 items again and again. That means - QSettings reads ENTIRE array in beginReadArray() function but then does not CLEAR the rest of array after "size" items. And later when writing array with beginWriteArray() it writes entire buffer but not only it's size() items.

      Solution - 1) after entire array was read to internal QSettings buffer then all items with indexes greater or equal to "size" must be removed 2) before writing array internal QSettings buffer must be reduced to item with largest changed index.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            gourmand64 Gourmet
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes