PocketMatrix forums

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

Destroy CGapiSurface?

What is the best way to free the memory that is occupied after a CreateSurface call?
I tried to delete just the object that was containing the CGapiSurface but that didn't free anything. Now I call CreateSurface(0,0,0,0); just before I remove the object but there must be a better way I think?
Or should I do a delete on the surface in the destructor but thats only for pointers isn't?
warmi · 23 Apr 2003, 22:32 UTC — Deletion
Well, this is a standard C++ stuff.
If you allocated memory for the object from the heap you can delete the entire thing with ‘delete’ ( I assume that CGapiSurface will delete its internal memory buffers properly.)
If you want to keep the object around and simply get rid of all that memory it allocated internally then CreateSurface(0,0,0,0) is the only way I can think of at this point.
Yes that is what I thought. But I doesn't seem to be the case. The object is the deleted but the surface within that object still occupies memory after the object has been deleted. Maybe this had something to do with GD110 / GD 200 but I doubt that. I'll look over my code once more mayby I'm doing something wrong.
Krelis: Please look through your code. All GapiDraw objects automatically free all resources when they are destroyed. This should be the case also with GapiDraw 1.10.
It might be a good idea to add a Clear() function to the surface class. This would be easier for first-time users. I remember searching for such a function when I started.

It could be as simple as

Code:

// clear the surface and all related data
HRESULT CGapiSurface::Clear(void)
{
return CreateSurface(0,0,0);
}
or as complex as freeing some more internal structures...

Who knows what mysteries lie in the GapiDraw's source code! ;)

--Eric
efortier: Most surfaces already have a protected function called FreeResources(). I could just make that public and it's done...

:) Right now with the "serious" code optimizations in 2.0, the code is actually beginning to look kind of mysterious.. ;)