Possible memory leak

2005-06-03
2012-11-13
  • Stephen Sherbert

    I am a new user searching for a fast text editor. 

    I installed version 3.0, and watched my task manager as I opened and closed a few files.  The memory usage goes up when I open a file, but never goes back down upon closing the file.  If I open/close the same file over and over the memory still increases so there is no caching or internal memory management that I can detect.  This looks like a run-of-the-mill memory leak.

    Any suggestions? Perhaps this is a new bug and an older version will perform better than this?

     
    • Josh Harris

      Josh Harris - 2005-08-23

      I've noticed the same problem.  I then tried Scite, which is the editor from the programmers of Scintilla (the editing component used by Notepad++) and it doesn't release the memory when you close a document, but it does release it when you close a document and then open another one.

      Notepad++ doesn't ever release the memory until you close the program.  I even tried the first available version of Notepad++ and it has the same problem.  I've tried it on two different machines (WinXP SP1 and WinXP SP2).  I've been seaching through the source but I'm having no luck finding the problem.

       
    • Josh Harris

      Josh Harris - 2005-08-24

      I have actually made some headway with this issue.  Adding two lines of code to "ScintillaEditView.cpp" and swapping two lines of code in "DocTabView.cpp" seems to help with releasing the memory for closed documents.  Unfortunately, the changes made to "ScintillaEditView.cpp" have been causing the program to occaissionally crash.  I'm still working on it though.

      I am testing it by opening a 94MB text file.  While the file is open, Notepad++ uses 217MB of memory.  With standard versions of Notepad++, when I close this file and reopen it memory usage doubles to 434MB.  With the modifications I have made, memory drops down to 7MB when I close it and back up to about 240MB when I reopen it.

      It still doesn't seem to be releasing all of the memory and, of course it crashes now, but it looks promising so far.

       
      • Don HO

        Don HO - 2005-08-24

        Josh,

        I'm glad that you're working on it, because I was on it and I have no idea about this problem. It seems come from Scintilla ( the bad usage perhaps? ), but I checked their online document :
        http://scintilla.sourceforge.net/ScintillaDoc.html

        and I don't think the usage of scintilla (in DocTabView.cpp) is incorrect.

        If you find something, please let me know.

        Thank you

        Don

         
    • Josh Harris

      Josh Harris - 2005-08-24

      Actually, after I posted the message last night, I removed the changes I made to "DocTabView.cpp" ( in function closeCurrentDoc, I had swapped lines 96 and 97 which placed closeDocAt(0) above newDoc() ) and tried it with just the changes made to "ScintillaEditView.cpp."  I haven't had a crash yet and most of the memory still seems to get released.

      I've just been sort of fumbling around, changing and adding code here and there so I have no idea if my changes are the right way to do things.  I'll post them here so that you and others more experienced can look into them further.  ScintillaDoc.html says that "you must balance each call to SCI_CREATEDOCUMENT or SCI_ADDREFDOCUMENT with a call to SCI_RELEASEDOCUMENT."  In closeDocAt, there is a call to SCI_RELEASEDOCUMENT but in closeCurrentDoc there is not.  In activateDocAt, there is a call to SCI_ADDREFDOCUMENT but no call to SCI_RELEASEDOCUMENT (there is a call to SCI_SETDOCPOINTER which is supposed to decrement the ref count but I added a call to SCI_RELEASEDOCUMENT anyway).

      ScintillaEditView.cpp
      In function activateDocAt, line 681 there is a call to SCI_ADDREFDOCUMENT.  I added a call to SCI_RELEASEDOCUMENT on line 686 after the call to SCI_SETDOCPOINTER.

      execute(SCI_RELEASEDOCUMENT, 0, _buffers[index]._doc);

      In function closeCurrentDoc, line 817 there is a call to SCI_SETDOCPOINTER.  I added a call to SCI_RELEASEDOCUMENT on line 818.

      execute(SCI_RELEASEDOCUMENT, 0, _buffers[_currentIndex]._doc);

       
      • Don HO

        Don HO - 2005-08-25

        EXCELLENT WORK Josh!

        It's enough just to modify "ScintillaEditView.cpp" (to add 2 lines of SCI_RELEASEDOCUMENT in activateDocAt and closeCurrentDoc), no need to touch "DocTabView.cpp".

        I'll never add these 2 lines myself because it seems correct what I've done according to the Scintilla Online Document.

        Thank you Josh, you just terminated my nightmare!!!

        Don

         
    • Josh Harris

      Josh Harris - 2005-08-24

      Another easy way to see the memory leak: open a fresh copy of Notepad++ with no document and hold down ctrl w.  This will continually create new documents.  By the time the new doc counter got to 1000 (it crashed there, by the way) memory usage had jumped from 4MB to about 19MB.  With the changes I made memory usage never changes.