Patch #2796 2009-07-30 20:09
techy
Various memory problem fixes (part 2)- Download
- 2796-Various_memory.patch (1.5 KB)
Index: src/sdk/filemanager.cpp
===================================================================
--- src/sdk/filemanager.cpp (revision 5716)
+++ src/sdk/filemanager.cpp (working copy)
@@ -26,6 +26,7 @@
LoaderBase::~LoaderBase()
{
+ WaitReady();
delete[] data;
};
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (revision 5716)
+++ src/sdk/editormanager.cpp (working copy)
@@ -421,11 +421,7 @@
cbEditor* EditorManager::Open(const wxString& filename, int pos, ProjectFile* data)
{
- LoaderBase* fileLdr = Manager::Get()->GetFileManager()->Load(filename);
- if (!fileLdr)
- return 0;
-
- return Open(fileLdr, filename, pos, data);
+ return Open(NULL, filename, pos, data);
}
cbEditor* EditorManager::Open(LoaderBase* fileLdr, const wxString& filename, int pos,ProjectFile* data)
@@ -460,13 +456,18 @@
if (!ed)
{
- ed = new cbEditor(m_pNotebook, fileLdr, fname, m_Theme);
- if (ed->IsOK())
- AddEditorBase(ed);
- else
+ if (!fileLdr)
+ fileLdr = Manager::Get()->GetFileManager()->Load(filename);
+ if (fileLdr)
{
- ed->Destroy();
- ed = NULL;
+ ed = new cbEditor(m_pNotebook, fileLdr, fname, m_Theme);
+ if (ed->IsOK())
+ AddEditorBase(ed);
+ else
+ {
+ ed->Destroy();
+ ed = NULL;
+ }
}
}
History
Currently when opening a file with
cbEditor* EditorManager::Open(const wxString& filename, int pos, ProjectFile* data)
a loader is first created and then passed to
cbEditor* EditorManager::Open(LoaderBase* fileLdr, const wxString& filename, int pos,ProjectFile* data)
However, the second mentioned function doesn't use this loader when the file is already opened and just returns the corresponding editor. In this case the loader is not deallocated which leads to a memory leak.
This patch doesn't create a loader when the file is already opened. As a side effect, switching between opened files is considerably faster on a (rather ancient) linux I use at work because the file isn't loaded unnecessarily every time I switch between already opened files.
Are you planning to apply the patch? This is the most important of my memory-problem fixes - the application leaks the complete contents of the file every time you switch the buffer e.g. by F11. The other memory fixes were just cosmetic to make valgrind to shut up.
To see the leaks, repeat the following:
1. Create a HUGE (several MB) source and header file and insert them into a project.
2. Start whatever you use to see how much memory a process occupies.
3. Start pressing F11 and see how the memory usage increases.
Yes, I'll commit it (soon, probably). I've tested it very heavy and a long time and wanted Linux devs to give it a try, too. I still got no feedback which is good (because it means nothing bad happens) bt still waiting for the agreement.
Good to hear! I have been using this patch under SUSE 9 and SLES 10 at work (plus Ubuntu on my home machine) during the last 4 month without any issues.