PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

How to unload surfaces

Is there a way to unload surface such that they can free up memory used by ocupied images.

I am aware of the delete function but once deleted the variable cannot be used again.

Currently, when I load other images to the same variable, system memory increase rapidly until application hang due to lack of memory.

I use GIF images in my application.

I have also tried preload all images at the begining of the application, but the memory used is unacceptable (too big 12mb).

Is m_bOwnMemory useful in this situation, and how to use it?

thanks
Just use delete. You cannot re-use a Surface object to load a different image (just like in DirectX). What you want is probably something like this:

Code:

Surface* myimage = LoadImage( "image1.gif" );
// use myimage
delete myimage;
myimage = 0;

// later on

myimage = LoadImage( "image2.gif" );
// use image
delete myimage;
myimage = 0;


The idea is that you load an image when you need it. You delete the surface when you are done with it. This way you minimize memory usage.
Thanks. That's what I want....
Code:
myimage = LoadImage( "image2.gif" );
delete myimage;
myimage = 0;


Why to use
myimage = NULL;?
I thought that after deleting it would take this value automatically, or it is just safety?
BIGBEN wrote:Why to use
myimage = NULL;?
I thought that after deleting it would take this value automatically, or it is just safety?


No it won't take "NULL" automatically and yes it is safety.
BIGBEN:

If you need this kind of functionality just create your own wrapper around PHAL surface and do whatever you want.

Create methods like xxx.createSurface(..) , copy constructors etc.
Thank you, but I'm absolutely pleased with the functionality provided by PocketFrog on top of Pocket Hal :)
Just waiting something new in PF about PNG's :lol:

And fogot to ask: is it right that I cannot overload standart delete operator for a Surface * that it would delete and assign to the pointer NULL automatically?