Skip to content
  • 0 Votes
    12 Posts
    2k Views
    T

    @Christian-Ehrlicher said in How avoid memory leak with GUI programming:

    @TheEnigmist said in How avoid memory leak with GUI programming:

    VS points to p = p.scaled line that add every time 10k byte of data (50x50x4 bytes), and each time I create and detroy the widget where that QAbstractTableModel is I see in memory that all that Pixmap are never destroyed.

    There is no leak and can't be one - you should take a look into QPixmapCache and for the sake of performance and implicit sharing don't load the pixmap in your data() method every time.

    Yeah I just found out that I was really wrong with that :( I will fix it right now!
    So I can go over when see pixmap in my allocated memory due to QPixmapCache. Ofc is always better to improve my code and don't load so many times a pixmap!

    @Chris-Kawa said in How avoid memory leak with GUI programming:

    @TheEnigmist said in How avoid memory leak with GUI programming:

    So if I'm not wrong what is cached is not the file on disk, but its scaled version

    No. How would Qt know that it's the same pixmap? What's cached is the pixmap that you create from a file, and the path (with some additional info) becomes a key to look it up in the cache.

    I see, but why the debugger points me to the scaled() function when looking for the allocated memory istance?

  • 0 Votes
    14 Posts
    3k Views
    SGaistS

    Anyone can contribute to the documentation, the code, etc. You have to follow the procedures and rules but it's not some walled garden.

  • 1 Votes
    7 Posts
    8k Views
    ?

    If someone needs a comprehensive 8 pages long explanation for what's exactly happening here, I recommend reading "Item 22: When using the Pimpl Idiom, define special member functions in the implementation file" from "Effective Modern C++" by Scott Meyers.

  • 0 Votes
    8 Posts
    6k Views
    kshegunovK

    @SGaist
    It happens even to the best ... at the very least we both support it, so that has to account for something ;)