© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
35 replies
Sound

✅ Memory leaks and idk how to solve them

Why does the following code produce memory leaks? Shouldn't
bg
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();
            }
            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();
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Need help with some memory leaks
C#CC# / help
4mo ago
✅ Process API: Memory Leaks in Windows (?)
C#CC# / help
13mo ago
How to solve?
C#CC# / help
3y ago
Memory leaks with OpenFileDIalog, SaveFIleDialog, and DataGridView in WinForms
C#CC# / help
2y ago