Notebook icon indicating copy to clipboard operation
Notebook copied to clipboard

Memory leak from undeleted Renderers

Open ga2k opened this issue 5 years ago • 1 comments

I have found that there is a memory leak from each clRenderer because they are created by "new" and stored by pointer in ms_Renderers, but are never deleted.

I have new code that fixes the issue when the Notebook goes out of scope, but I can't fork and PR because I get 403 forbidden accessing your repository.

Here are the changes I made.

  1. clTabRenderer.h : public: static void DeleteRenderers(void) { for (auto& r : ms_Renderes) delete r.second; }
  2. Notepad.cpp : Notebook::~Notebook() { clTabRenderer::DeleteRenderers(); }

That's it. It works.

ga2k avatar Sep 19 '20 03:09 ga2k

Thanks for the fix. I was facing the same issue but your fix did not work for me directly. I am using two instances of the Notebook. When the destructor is called for the first instance it works but then I got an access violation error when deleting the second one. My fix was:

  • Setting the pointer to nullptr so that the following instances don't try to delete it again: static void DeleteRenderers(void) { for (auto& r : ms_Renderes) { if (r.second) { delete r.second; r.second = nullptr; } } }

I'm assuming having more than 2 instances of the Notebook will also work but not tested. Thanks again :)

dailybeats avatar Aug 28 '22 00:08 dailybeats