×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    17

    QPixmap uses to much of memory space even after using QPixmapCache

    Hi,

    I am developing an application, which requires to plot .png image on the screen. A maximum of 20 images can be placed and also, while scrolling left or right, images should also move. To handle this, i have to paint images in paintevent() function. Calling painevent so frequently, increases the umemory, The image size is 1KB, but with 20 pins on screen, and left scroll, images increase by about 0.5mb everytime.

    I have used this approach to put images on the screen:

    QPixmapCache::clear();
    m_BluePin = new QPixmap(":/images/pin-blue.png");
    p.drawPixmap(pt, *m_BluePin);
    delete m_BluePin;

    and 2nd approach:

    QPixmap blue_pixmap;
    if (!QPixmapCache::find(":/images/pin-blue.png", blue_pixmap)) {
    blue_pixmap = QPixmap(":/images/pin-blue.png");
    QPixmapCache::insert(":/images/pin-blue.png", blue_pixmap);
    }
    p.drawPixmap(blue_pt, blue_pixmap);

    Both seems to take same amount of space. Also, at later part of the application, I remove pins one after another, but this does not reduce the heap memory used. Instead it increases the memory.

    Is there a way, to clear the previous data of paintevent() before calling painteventevent() again?

    Thanks in advance.

  2. #2
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: QPixmap uses to much of memory space even after using QPixmapCache

    First off, leave QPixmapCache alone!! It works automatically, without your monkeying around with it.

    If you're only going to draw "pin-blue" once,
    Code:
    p.drawPixmap(pt, QPixmap(":/images/pin-blue.png"));
    should suffice.

    Even if you're drawing it multiple times, but separated in time by other operations, the above is probably the best approach. The QPixmapCache will automatically manage the images with its LRU cache.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    17

    Re: QPixmap uses to much of memory space even after using QPixmapCache

    Thanks for the suggestion..

    I tried the approach suggested by you, but still I see that the memory is increasing. The problem is that in one paint event, i have place, as much as 20 pins. and whenever i press the left or right key, all the 20 pins move on the acreen accordingly, and therefore, another set of 20 pins are drawn with every key event. Moreover, at later stage, the memory used is not reclaimed when these pins are removed from the screen. Please suggest any approach which will help in handling this situation.


  4. #4
    Regular Contributor
    Join Date
    Aug 2008
    Posts
    95

    Re: QPixmap uses to much of memory space even after using QPixmapCache

    If files are so small (total 20kB), i'll try to preload on heap all files and then display ... i thing that loading and display everytime spend much time.

  5. #5
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: QPixmap uses to much of memory space even after using QPixmapCache

    QPixmapCache is a CACHE. That means that it will continue to cache new images until it reaches its target cache size, after which it will manage them in an LRU (least recently used) fashion. If, after QPixmapCache should have achieved "steady state", memory use continues to climb, then likely you have a leak somewhere.

Similar Threads

  1. Memory Space Problem
    By contra03 in forum Symbian
    Replies: 5
    Last Post: 2009-12-02, 10:19
  2. Nokia 3650 - No memory space in C:\
    By mireq9 in forum General Development Questions
    Replies: 6
    Last Post: 2009-05-19, 12:00
  3. The memory space in Nokia 6300???
    By Jayant61 in forum General Development Questions
    Replies: 2
    Last Post: 2008-12-09, 16:41
  4. Flashlite - which phone has largest memory space
    By Sludge in forum [Archived] Flash Lite on Nokia Devices
    Replies: 6
    Last Post: 2008-01-25, 14:54

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×