How do I free the memory used up in loading a DLL?
How do I free the memory used up in loading a DLL?
I am trying to run an application that loads a dll into memory, runs a function inside of it named DllMain() then immediately closes the library and loads different DLL with the same function name then runs it and immediately closes the library again. However, the program uses more and more ram everytime it loads the Dll eventually using all available ram.
How do I free the used memory so I can load another DLL again without using up all of my ram?
How do I free the used memory so I can load another DLL again without using up all of my ram?
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: How do I free the memory used up in loading a DLL?
Maybe the dll files have a memory leak?
Re: How do I free the memory used up in loading a DLL?
Hmm, if the DLL allocates 1024 bytes of data and doesn't free the memory afterwards does it still continue to persist inside of the program even after the library is closed?
[Edit] I just tried with a blank DLL that opens a single messagebox..
Here is my procedure that loads the dll:
It's placed inside of the main loop and called very very often.
[Edit] I just tried with a blank DLL that opens a single messagebox..
Here is my procedure that loads the dll:
It's placed inside of the main loop and called very very often.
Code: Select all
Prototype.l protoDLLMain()
Procedure LoadDLL()
directoryEntry = ExamineDirectory(#PB_Any,"common\","*.dll")
While NextDirectoryEntry(directoryEntry)
libraryEntry = OpenLibrary(#PB_Any,"common\"+DirectoryEntryName(directoryEntry))
DLLMain.protoDLLMain = GetFunction(libraryEntry,"DLLMain")
DLLMain()
CloseLibrary(libraryEntry)
Wend
FinishDirectory(directoryEntry)
EndProcedure
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: How do I free the memory used up in loading a DLL?
Yes.Nituvious wrote:Hmm, if the DLL allocates 1024 bytes of data and doesn't free the memory afterwards does it still continue to persist inside of the program even after the library is closed?
Re: How do I free the memory used up in loading a DLL?
Even with just a simple messagebox DLL the program still seems to use up all of my ram eventually. I think the issue is my loadDLL function. Any ideas?
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: How do I free the memory used up in loading a DLL?
Ugh, I still can't seem to fix this issue. I think the issue is within my loadDLL function since loading a simple messagebox dll still causes a memory leak(if that's even the term for this).
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: How do I free the memory used up in loading a DLL?
I can confirm this. It looks like the use of strings inside the dll is the problem. It must be a bug in PB.
Re: How do I free the memory used up in loading a DLL?
Maybe I can rely on API to get over this bug?
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: How do I free the memory used up in loading a DLL?
The simple way would be to only load each dll once.
Re: How do I free the memory used up in loading a DLL?
I wanted to do it that way originally but I can't because the loaded dll's should be removed or altered while the host program is running. Additional libraries can also be added while the program runs as well.Trond wrote:The simple way would be to only load each dll once.
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: How do I free the memory used up in loading a DLL?
Do you think I could fix this memory leak by putting the function that loads the DLL in a thread and then ending that thread after the function has called? I haven't had a chance to try yet, I will when I get home though.
▓▓▓▓▓▒▒▒▒▒░░░░░
Re: How do I free the memory used up in loading a DLL?
If it is a PB bug -> write a bug message.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Re: How do I free the memory used up in loading a DLL?
i dont think it's really a bug in PB, because you didn't really free the library; need to call FreeLibrary() in win32
just have to make your own FreeLibrary() procedure
just have to make your own FreeLibrary() procedure
Code: Select all
Procedure FreeLibrary(library_no)
FreeLibrary_(LibraryID(library_no))
EndProcedure
Re: How do I free the memory used up in loading a DLL?
kandl: You don't need to use FreeLibrary_() when you use CloseLibrary(), and even with FreeLibrary_() the memory usage grows in the same fashion.