Home
Developer Resources
QNX RTOS v4
QNX RTOS v4 Knowledge Base

QNX RTOS v4 Knowledge Base

Foundry27
Foundry27
QNX RTOS v4 project
Resources

QNX RTOS v4 Knowledge Base

Title Loading a JPG file using PxLoadImage()
Ref. No. QNX.000009899
Category(ies) Development
Issue We are using the PxLoadImage() function many times to load a JPG file that will be displayed in a widget. However, we found out that the memory is decreased every time the PxLoadImage() function is called.
Is there a way to free up the previous memory before a new image is loaded?
Solution The only memory that PxLoadImage() allocates for you is the image's memory, so you can free it.

x09/*free image*/
x09image->flags = Ph_RELEASE_IMAGE | Ph_RELEASE_PALETTE | Ph_RELEASE_TRANSPARENCY_MASK | Ph_RELEASE_GHOST_BITMAP;

x09PhReleaseImage(image);
x09free(image);

PhReleaseImage() frees the members of the image structure that are indicated in image->flags. PxLoadImage() does not set any of the flags, so you have to set the flags yourself before calling PhReleaseImage().
Then, free the image structure.