C#C
C#3y ago
Sound

✅ Memory leaks and idk how to solve them

Why does the following code produce memory leaks? Shouldn't bg get deleted and then reallocated?

            Background bg = new();

            while (!Raylib.WindowShouldClose())
            {
                Raylib.BeginDrawing();
             
                bg.Dispose();
                bg=new();

                Raylib.DrawText(Raylib.GetFPS().ToString(), 10, 10, 20, Color.RED);
                
                Raylib.EndDrawing();
            }

bg.Dispose();
bg=new();
Why do these constantly allocate new memory and the old one doesn t get freed up? And how do i make it work?
Was this page helpful?