sdl-gpu
sdl-gpu copied to clipboard
Why creating but freeing many targets consumes memory from the os and doesnt really give it back ?
i am contstantly resizing a GPU_Target each time the user resizes an embedded virtual window in the gui , i do resizing by recreatiing the target , and i create it using GPU_LoadTarget () , it looks like if i do it so frequently , i will consume too much memory even when i free each old image/target , why i am having this issue ? can i resize it in an other way ? can i free it compleltely and give all the used memory back to the system
Now after debugging i can say that i found the path to the reason: creating and freeing images works fine , but creating and freeing targets doesnt really free every allocated byte , so there will still be some comsumed memory , that causes the issue
solution: GPU_FreeTarget() does not free the image used to load the target , ( this option can be added to sdl_gpu using flags and a smart decision taker that knows when to do it ( free the parent image ) ) , because that image will be useless ) we can put a function GPU_CreateTarget() and let GPU_FreeTarget() frees the image if that targed was created using that first function
solved : You only need to free the source image and not the target , this is a weird implementation , the loaded target will be freed , but what about the opposite ? both ways should be safe
Yes, it is perhaps weird. The image is the owner of the memory and serves as the base for the target. In other words, the lifetime of a target is necessarily shorter than the image. Freeing the target only removes it from the image and does nothing further to the image.
I'm not sure that having it work both ways would be possible. Freeing one would leave some memory in order to allow safe usage/freeing of the other. Something that would be possible would be to make targets increment and decrement the image refcount so you could immediately free the image after loading the target. That might be getting into even weirder territory, though.
we can add a function , let name be : 'GPU_CreateTraget()' , so instead the user loaded a target from image , he can also use this path and create tha target directly , now this new target will have a flag set to 'true' indicates that the underlying image should be freed with the target ... Other solution : GPU_FreeTargetAndImage() Other solution : GPU_Image* GPU_CreateTargetsLoadingImage() { .... return img ;}
this function generates a special image that is allowed to be freed when child targets are freed ...
pick your best or suggest