Garbage Collection Question

Blitz3D Forums/Blitz3D Programming/Garbage Collection Question

jfk EO-11110(Posted 2007) [#1]
I wonder what's gonna happen with those brushes and or textures that are no longer used by a surface. EG:

brush=GetSurfaceBrush(surf)
PaintSurface, surf,brush

This will create a clone of the original brush of the surface. After painting the clone on the surface, the original brush is no longer in use. Is it removed from memory automaticly, or do I have to expect a memory leak?

Well while I'm writing this I just realize, I could test this with a little test app, as long as Vram is affected...

Maybe somebody else already knows what's up with it.


Stevie G(Posted 2007) [#2]
From the docs ..


Remember, GetSurfaceBrush actually creates a new brush so don't forget to free it afterwards using FreeBrush to prevent memory leaks



Stevie


jfk EO-11110(Posted 2007) [#3]
Yes of course I know, thanks. I meant: if the original brush is no longer used because it was replaced, will it be released for memory?


b32(Posted 2007) [#4]
I think the brush is freed. You remember my post from the other time? When a brush remains in memory, and you update the file it doesn't load the new file.
So I wrote this code to test, it loads a mesh, applies a new brush to it and overwrites the original texture. Then it reloads the original texture and reapplies it to the mesh. If it wasn't freed, the new version shouldn't show:



jfk EO-11110(Posted 2007) [#5]
Well, using an already loaded texture does not mean it will clean up menory automaticly when the texture is no longer required.

Basicly, my question is this:

When I load or create a texture like this:

tex=LoadTexture("x.bmp")

then it will of course not free the texture as soon as it is no longer used, because right after creation it isn't used by any mesh anyway. The Command FreeTexture is then used to get rid of it.
But what is gonna happen if a Texture was loaded with a mesh, using the Command LoadMesh()? The only way to get a brush handle of a loaded mesh is to use GetSurfaceBrush, but this will not return the handle of the real brush in use, but it will create a clone of that brush. So you have no access to the original brush (and the brushes textures) and therefor you can't free them using FreeBrush and FreeTexture. So when you change the texture of a loaded mesh, this would mean there's a serious memory leak (the size of the textures!)


b32(Posted 2007) [#6]
Yes, that is what the test was all about.
I believe that if you load a mesh with an inclusive texture, then apply a new brush to it, the inclusive texture is freed.

(1) Load a mesh, with a texture applied to it
mesh = "cube.x" texture = "cube.bmp"
As you said, the texture is loaded with LoadMesh rather than LoadTexture/Brush
(2) Replace the "cube.bmp" file with another file and reload the same mesh.
Now, the second mesh has still the original version of "cube.bmp" applied to it.

However, if you paint the mesh with another, arbitrary brush before reloading the mesh, the new version does appear. This must mean that the original brush was freed.


jfk EO-11110(Posted 2007) [#7]
Ok, I see, thanks a lot!