nanogui: Server don't free memory from images after releasing it with GrFreeImage
Subject:
Server don't free memory from images after releasing it with GrFreeImage
From:
"Michael Augst" ####@####.####
Date:
19 Oct 2005 09:28:15 +0100
Message-Id: <24812.1129710467@www44.gmx.net>
For loading a images i created the nxImage class.
It works fine with many accesses and often switching the images,
but after loading and unloading the background (320x240) and
switching to a icon 32x32 the used memory by the server stays
the same. After this i can load the background again without
any changing of the used memory by the server.
Meanwile i have about 20 icons and used memory goes up at the
beginning from 2400 Kb (no images) to 2700 Kb (full 24 icons +
background) but never decreases even the progamm is running
in a part with only 4 icons (the max are 20 in a selectionmenu).
By the way the backgroundimage (320x240) is allways present and
in the beginning of the programm the 4 icon menu + background
takes only 2600 Kb of memory.
As you can see in the code i unload the image before i load a
new one and i allways free the last image after im finished the
drawing, aswell as the destructor would do if i forget.
So my question is when the server frees the used memory?
Or have i a bad code?
// i know ;-) it is not perfect in style
Or have i free it my self by a client->server call?
// CLASS SAMPEL //
class nxImage
{
public:
GR_IMAGE_ID image_id;
int width, height;
void nxImage::LoadImage(char* path);
void nxImage::DrawImage(GR_WINDOW_ID win_id, GR_GC_ID gc_id,
int start_x, int start_y);
void nxImage::FreeImage(void);
nxImage::nxImage(); // set image_id to 0
nxImage::~nxImage(); // free image if not done bevor
private:
/* nothing for now */
}; // CLASS nxImage
void nxImage::LoadImage(char* path)
{
// holds the info, given by the sever, about the image
GR_IMAGE_INFO image_info;
// free current image if allready present
if (image_id) {GrFreeImage(image_id);}
if (!(image_id = GrLoadImageFromFile(path, 0))) // load new image
{
fprintf(stderr, "Can't load %s image file\n", path);
exit(-1);
}//if()
// get info of the current loaded image form server
GrGetImageInfo(image_id, &image_info);
width = image_info.width; // set height & width of the image
height = image_info.height;
} // nxImage.LoadImage()
void nxImage::DrawImage(GR_WINDOW_ID win_id, GR_GC_ID gc_id,
int start_x, int start_y)
{
// Draws the image to the screen
GrDrawImageToFit(win_id, gc_id,
start_x, start_y,
width, height, image_id);
} // nxImage.DrawImage()
void nxImage::FreeImage(void)
{
// free current image if allready present
if (image_id) {GrFreeImage(image_id);}
image_id = 0;
} // nxImage::FreeImage()
nxImage::nxImage()
{
image_id = 0; // set zero to show that no image is allready loaded
} // nxImage::nxImage()
nxImage::~nxImage()
{ // free current image if allready present
if (image_id) {GrFreeImage(image_id);}
} // nxImage::~nxImage()
// Code EXAMPLE //
#define BACK "GIF/back5.gif" /* background 320x240 */
#define DESO "GIF/deso.gif" /* company logo 130x60 */
#define ICON "GIF/icon.gif" /* a icon 32x32 */
nxImage image; // create a new image object
image.LoadImage(BACK); // loading the first image -> memory alocated
image.DrawImage(my_x.output_window, my_x.gc, 0, 0);
image.LoadImage(DESO);
image.DrawImage(my_x.output_window, my_x.gc,
(WHIDE/2)-(image.width/2), 100);
image.LoadImage(ICON);
image.DrawImage(my_x.output_window, my_x.gc, 40, 210)
image.FreeImage();
// freeing the last image -> memory shoud be completly delocated
// but this isn't happening(tested on runtime with KDE Process Table)
--
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner