angeluriot / Dimension3D

A simple graphics library (2D, 3D and windows).
MIT License
46 stars 10 forks source link

Memory leaks #12

Closed hamyyy closed 11 months ago

hamyyy commented 12 months ago

Great library so far, but I noticed you use raw pointers a lot in various classes. almost all cone() functions create new pointers (which is okay if managed properly), but then almost every setter function calls clone() without freeing the previous pointer. so if we set_XXX() multiple times we will end up with many loose pointers AKA a memory leak.

try putting this in your main loop and watch the memory go:

for (int i = 0; i < 1000; i++)
{
    scene.set_controller(controller);
}

Yes, we would never want to set the controller every frame, but if I wanted to switch between two controllers it would leak memory every time.

I'd suggest using shared pointers, deleting the old pointer before setting the new one, or not clone at all and instead use the passed in parameter.

angeluriot commented 12 months ago

Thanks, I fixed it: 1e259f0e2d6ea14f5fd6568d7596e7aaf087b8e3