1. Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by CladStone Jul 25, 2009
- 1124 views
Maybe I'm just worried/curious about stuff that doesn't matter, but in the interest of "running a tight ship", I'm trying to figure out why what I see in Windows Task Manager doesn't seem to match up with what I would expect, so I'm wondering if someone could explain to me some basics of how Euphoria uses and releases memory, and how I can "force" it to take it or give it back, etc.
I realize that part of the issue may have to do with the way Task Manager reports memory usage, so any insights on that would help too.
A few examples:
1) I have some code where I explicitly allocate 32 MB of memory, but it doesn't show up in Task Manager. Does Task Manager not show you allocated memory, but rather only what is actually being used of that allocated memory?
2) I have another bit of code that loads a file and does some work with it. When I'm done, I want to be able to free up the extra space, so I say: mybigvar = {}. The first such statement produces NO effect whatsoever in Task Manager. The second such statement (e.g. myotherbigvar = {}) produces a small decrease (a couple hundred KB) which is well under the size of either of these variables.
3) Same example as #2, but with memory, not sequences. The file data itself was in a memory buffer, which I free, but doing so produces NO corresponding effect in Task Manager, though I'd expect to see a drop of about 500 KB.
2. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by LarryMiller Jul 25, 2009
- 1125 views
Maybe I'm just worried/curious about stuff that doesn't matter, but in the interest of "running a tight ship", I'm trying to figure out why what I see in Windows Task Manager doesn't seem to match up with what I would expect, so I'm wondering if someone could explain to me some basics of how Euphoria uses and releases memory, and how I can "force" it to take it or give it back, etc.
I realize that part of the issue may have to do with the way Task Manager reports memory usage, so any insights on that would help too.
A few examples:
1) I have some code where I explicitly allocate 32 MB of memory, but it doesn't show up in Task Manager. Does Task Manager not show you allocated memory, but rather only what is actually being used of that allocated memory?
2) I have another bit of code that loads a file and does some work with it. When I'm done, I want to be able to free up the extra space, so I say: mybigvar = {}. The first such statement produces NO effect whatsoever in Task Manager. The second such statement (e.g. myotherbigvar = {}) produces a small decrease (a couple hundred KB) which is well under the size of either of these variables.
3) Same example as #2, but with memory, not sequences. The file data itself was in a memory buffer, which I free, but doing so produces NO corresponding effect in Task Manager, though I'd expect to see a drop of about 500 KB.
I will only comment on #1. The others deal with Euphoria internals and there are others much better qualified to answer.
Windows, along with Linux and the Mac (OSX and later), uses a virtual mmeory system. Each application is given a 4GB virtual address space that is completely independent of physical memory size. The upper 2GB is common to all processes and the lower is private to each process. That is the default for Windows, other systems may vary. Applications never allocate or access physical memory directly. Physical memory resoureces are managed by the system.
When any application allocates memory it is actually allocating virtual address space. How much of this space will actually be populated with RAM is entirely up to the system. Many factors are considered, such as how the virtual address space is accessed, how much memory is available in the system, and the requirements of other processes. When RAM is assigned to a process it is the system that determines how long it gets to keep it, not the application. Applications can influence this to a degree but not control it.
Applications are never aware of any of this.
3. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by LarryMiller Jul 25, 2009
- 1089 views
I should add that internal memory management in Windows is VERY complex. The principles are not well known, even among computer professionals. I am by no means an expert, but I'm trying.
The Task Manager display in Windows can be difficult to interpret. Many of the numbers do not mean what is commonly believed. To really understand them you must understand how the system works, and that knowledge is not easily obtained.
4. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by CladStone Jul 25, 2009
- 1092 views
Thanks Larry, your posts are very helpful. You're right, it's pretty complex, and my mind is having to stretch a bit, but your first post even answered questions I hadn't yet asked. I found out a lot when I looked up the term "Commit Charge" which is apparently what the "Mem Usage" column in Task Manager really displays. I found there's also a "VM Size" column you can add, and it reflects my expectations much more closely, in regards to my (#1).
But even the "VM Size" stays (virtually) the same after I've cleared the big variables and freed the memory allocation, so maybe someone can give me some tips on #2 and #3.
5. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by CoJaBo Jul 25, 2009
- 1112 views
Thanks Larry, your posts are very helpful. You're right, it's pretty complex, and my mind is having to stretch a bit, but your first post even answered questions I hadn't yet asked. I found out a lot when I looked up the term "Commit Charge" which is apparently what the "Mem Usage" column in Task Manager really displays. I found there's also a "VM Size" column you can add, and it reflects my expectations much more closely, in regards to my (#1).
But even the "VM Size" stays (virtually) the same after I've cleared the big variables and freed the memory allocation, so maybe someone can give me some tips on #2 and #3.
Well I'm no expert on Windows memory allocation either, but it is likely that the Eu interpreter or maybe Windows itself is holding on to that memory for possible future use. If that is the case, I would expect that if you fill some other var with a lot of data it would reuse that memory, and you would see little or no increase in the VM size.
6. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by bernie Jul 25, 2009
- 1107 views
Thanks Larry, your posts are very helpful. You're right, it's pretty complex, and my mind is having to stretch a bit, but your first post even answered questions I hadn't yet asked. I found out a lot when I looked up the term "Commit Charge" which is apparently what the "Mem Usage" column in Task Manager really displays. I found there's also a "VM Size" column you can add, and it reflects my expectations much more closely, in regards to my (#1).
But even the "VM Size" stays (virtually) the same after I've cleared the big variables and freed the memory allocation, so maybe someone can give me some tips on #2 and #3.
Well I'm no expert on Windows memory allocation either, but it is likely that the Eu interpreter or maybe Windows itself is holding on to that memory for possible future use. If that is the case, I would expect that if you fill some other var with a lot of data it would reuse that memory, and you would see little or no increase in the VM size.
If you are using ver 3.1 euphoria:
When the interpreter first starts it is allocated local heap memory.
That is fixed amount that will not change while program is running.
The program allocates memory from that heap, releasing memory in the program just returns it to the heap pool.
If you are running ver. 4.0
It depends on the Operating System that you are using how euphoria handles memory.
It may use the heap or virtual memory allocation.
7. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 30, 2009
- 994 views
- Last edited Feb 03, 2011
There also may be a bug in 3.1 Euphoria -- it definitely changed how it releases memory under Windows between 2.5 and 3.0 (or maybe it was 3.0 and 3.1, can't remember). It used to be you could use a huge chunk of memory processing something, and then release it by setting the variables to null (i.e. var = {}). This stopped working in v3.1. It then held on to the memory, and you could re-use it (without it growing further, so it wasn't a total memory leak), but if you weren't going to reuse, you could never get the application to give it up. I had a number of pre-3.1 programs that did some big processing like this when they started up, but then released it. I had to rewrite them for 3.1 and break them up into two programs chained together because they were long-running programs and they'd continue hogging system resources forever after they were finished with those resources. I used to be able to run several of these programs simulataneously, but with 3.1 it would practically crash the system.
I reported this several times, but couldn't get anyone to pay attention, only getting the response that memory handling hadn't changed and it was "complicated". But it can be easily shown running the same code that v2.5 will release the memory and v3.1 won't. Haven't tried v4.0 yet.
8. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by bernie Jul 30, 2009
- 1002 views
There also may be a bug in 3.1 Euphoria it definitely changed how it releases memory under Windows between 2.5 and 3.0 (or maybe it was 3.0 and 3.1, can't remember). It used to be you could use a huge chunk of memory processing something, and then release it by setting the variables to null (i.e. var = {}). This stopped working in v3.1. It then held on to the memory, and you could re-use it (without it growing further, so it wasn't a total memory leak), but if you weren't going to reuse, you could never get the application to give it up. I had a number of pre-3.1 programs that did some big processing like this when they started up, but then released it. I had to rewrite them for 3.1 and break them up into two programs chained together because they were long-running programs and they'd continue hogging system resources forever after they were finished with those resources. I used to be able to run several of these programs simulataneously, but with 3.1 it would practically crash the system.
I reported this several times, but couldn't get anyone to pay attention, only getting the response that memory handling hadn't changed and it was "complicated". But it can be easily shown running the same code that v2.5 will release the memory and v3.1 won't. Haven't tried v4.0 yet.
Andy:
Are using ver. 3.1.1 ?
This is may have had something to do with it.
Euphoria Release Notes
Version 3.1.1 August 2007:
This release is a minor update to fix some bugs.
Bug Fixes
- bug fixed: A storage leak (memory allocated but never freed) was introduced in version 3.1, on the Linux and FreeBSD platforms. Fixed by Matthew Lewis.
Also if you are using win32lib it used some of its own
memory management and the version you are using may have
a bug in it.
9. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by mattlewis (admin) Jul 30, 2009
- 995 views
There also may be a bug in 3.1 Euphoria it definitely changed how it releases memory under Windows between 2.5 and 3.0 (or maybe it was 3.0 and 3.1, can't remember). It used to be you could use a huge chunk of memory processing something, and then release it by setting the variables to null (i.e. var = {}). This stopped working in v3.1. It then held on to the memory, and you could re-use it (without it growing further, so it wasn't a total memory leak), but if you weren't going to reuse, you could never get the application to give it up. I had a number of pre-3.1 programs that did some big processing like this when they started up, but then released it. I had to rewrite them for 3.1 and break them up into two programs chained together because they were long-running programs and they'd continue hogging system resources forever after they were finished with those resources. I used to be able to run several of these programs simulataneously, but with 3.1 it would practically crash the system.
I reported this several times, but couldn't get anyone to pay attention, only getting the response that memory handling hadn't changed and it was "complicated". But it can be easily shown running the same code that v2.5 will release the memory and v3.1 won't. Haven't tried v4.0 yet.
My recollection was that prior to 3.0, or so (I can't recall exactly, either), euphoria simply used the standard malloc() from watcom. This never released anything back to the OS. At this point, euphoria uses Windows' allocation routines. In both cases, euphoria uses an internal cache to speed up reuse of memory.
Matt
10. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by LarryMiller Jul 30, 2009
- 995 views
According to my understanding, earlier versions simply used the c malloc() function which did not release memory to the system. A large block of memory was recycled as needed. This was changed somewhere around version 3. I think the latter behaviour is to be prefered, but the practical differences aren't as great as you might think.
Applications don't allocate RAM, they allocate from their private address space. How much RAM they get to populate that address space is up to the OS, not the application. The OS bases it's decision on how the app is using the RAM it was assigned and how much is avaiable. If an application has a low page fault rate this indicates to the OS that the app probably has more RAM than it needs and will trim it back in favor of applications that need it more. If plenty of RAM is available this won't happen - but what does it matter?
A true memory leak is another matter entirely. In this case the application is continuously asking for more memory and never giving it back. If unchecked this can lead to the misbehaving app failing, and possibly others as well. The OS can't tell the difference between legitimate memory use and a leak.
I am sure that experienced developers know this already but others will not.
11. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 30, 2009
- 1015 views
- Last edited Feb 03, 2011
Gee, it seems like the opposite of what you guys are saying. In version 2.5, I can fill up a giant sequence that uses a ton of memory, release it (var = {}), and then that memory is once again available to other apps -- you can see this with a "free RAM" type program or in the task manager. In 3.1 (3.1.1 under Windows XP is what I'm using) and that same program keeps and holds the memory forever, PREVENTING me from using another copy of the same program simultaneously. Like I said, I had to rewrite some programs I'd been using for years on v2.5 because I wanted to switch to v3.1. Those are real-world consequences. I'm not imagining it.
I posted a simple example of this on the old forum, which I will now recycle here. Let's check it again.
clear_screen() object x x = {} for i = 1 to 50 do -- adjust if it grabs too much memory for your system ? i for j = 1 to 500 do x &= rand(repeat(1000,1000))/rand(repeat(1000,1000)) end for end for x = gets(0) ? x x = gets(0)
This program eats up a bunch of memory. Running it on v2.5, when it gets to 50, the task manager reports it using 684,188K. Now I hit enter (once), which replaces the entire "x" variable with a one-element sequence. You can actually watch the memory being released in blocks in the task manager all the way down to 4146K, basically nothing. It frees it all.
Ok, now same test with v3.1:
counter at 50: 684,164K
hit enter: 586,308K
About 90MB freed. Same exact results I got when I originally posted it. That memory is FREE in v2.5 for use in other apps. Not in v3.1.
In v3.1 it seems like it is releasing one block of memory only (which happens instantly). In v2.5 you can watch the memory being freed in stages; it takes 5 seconds or so to free it all.
However, like I said, it is not an outright leak. If you add a second memory-grabbing loop, like so:
x = {} for i = 1 to 50 do -- adjust if it grabs too much memory for your system ? i for j = 1 to 500 do x &= rand(repeat(1000,1000))/rand(repeat(1000,1000)) end for end for x = {} for i = 1 to 50 do -- adjust if it grabs too much memory for your system ? i for j = 1 to 500 do x &= rand(repeat(1000,1000))/rand(repeat(1000,1000)) end for end for x = gets(0) x = gets(0)
... then the amount of used memory stays stable after the first loop. So it does manage to reuse that memory. It is at least available to itself.
Anyone care to report what happens in v4.0?
12. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by DerekParnell (admin) Jul 30, 2009
- 1021 views
Anyone care to report what happens in v4.0?
Just tried your programs in v4 and it looks like v4 releass memory back to the operating system when your program fully dereferences a sequence. This means that when you set a sequence to an atom, and there are no other references to that sequence, the memory is given back to the operating system. This also happens to sequence variables, which are declared inside routines, when the routine exits.
procedure test() sequence AA AA = repeat(0, 40_000_000) -- allocate 160 Meg of space sleep(3) end procedure -- RAM is returned at this point.
13. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 30, 2009
- 999 views
Anyone care to report what happens in v4.0?
Just tried your programs in v4 and it looks like v4 releass memory back to the operating system when your program fully dereferences a sequence. This means that when you set a sequence to an atom, and there are no other references to that sequence, the memory is given back to the operating system. This also happens to sequence variables, which are declared inside routines, when the routine exits.
Well, looks like I will have to try v4. Using an atom instead of an empty sequence doesn't help in v3.1. You say when you set to an atom AND there are no other references to the sequence. In what situation would there be another reference to the sequence? I know there would be another reference if there was another explicit reference (another variable) to it:
x = <big sequence> y = x x = 0 -- y still references big sequence, so memory is not released
But are there situations where I set all explicit references to atoms and there would still be an internal reference hanging around?
14. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by DerekParnell (admin) Jul 30, 2009
- 998 views
But are there situations where I set all explicit references to atoms and there would still be an internal reference hanging around?
There shouldn't be, so it would be a bug in Euphoria if there was. The programmer has control over this aspect, but watch out for third-party libraries. If they take a copy of your sequence (parameter), your program might not know about it, even though Euphoria does, of course.
sequence AA = <some huge value> libProc(AA) AA = 0 -- Frees RAM unless 'libProc' took a copy of it.
15. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 30, 2009
- 1000 views
- Last edited Jul 31, 2009
But are there situations where I set all explicit references to atoms and there would still be an internal reference hanging around?
There shouldn't be, so it would be a bug in Euphoria if there was. The programmer has control over this aspect, but watch out for third-party libraries. If they take a copy of your sequence (parameter), your program might not know about it, even though Euphoria does, of course.
sequence AA = <some huge value> libProc(AA) AA = 0 -- Frees RAM unless 'libProc' took a copy of it.
Yes, good. I'm pretty careful where I go leaving my 100s-of-MB-large variables, so it should be fine.
Thanks for checking it out.
16. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 31, 2009
- 1007 views
- Last edited Feb 03, 2011
Sorry, no dice.
I downloaded 4.03a and ran the code. It does not free the RAM on my system. This is Windows XP Pro. What were you using Derek? (Does it free it on Vista? My laptop is Vista -- I could try that.) I've tried this on other machines with v3.1, and got the same result. I can't remember if I've tried Vista though.
What about the Eu version? Are you using 4.03a or a more bleeding-edge version? Any super-recent changes to memory handling, garbage collection?
Anyway, not only did it not free the RAM, but it used way more of it too. With the same code as before (my code, with the loops), when the counter is at 50 I get: 878,522K used, 200,000K more than before! And it doesn't free it either. After setting x = 0 (or x = {}, no difference), it only goes down to 780,696, still 100K more than the 3.1 version used maximum.
Now then, if I allocate all that memory, but don't really fill it up with anything, like with the x = repeat(0,40_000_00) statement, it will release it all. But of course I would be filling it up with stuff, usually floating point data like in my example. I also tried pre-allocating the sequence with a repeat statement, but that actually makes it worse -- it is noticeably slower running when filling up the sequence (using indexes instead of concat), and then it doesn't really free up anything at all when setting x = 0. And pre-allocating usually isn't an option anyway, because these giant variables get filled up reading in giant files with unknown amounts of data in them, doing big database operations, etc. It just isn't practical.
So from where I'm sitting, it appears we're going in the wrong direction! What did v2.5 do that made it release the memory -- something to do with the Watcom malloc? If we compiled with Borland or other, would it work differently?
Thoughts?
17. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by DerekParnell (admin) Jul 31, 2009
- 991 views
Sorry, no dice.
I downloaded 4.03a and ran the code. It does not free the RAM on my system. This is Windows XP Pro. What were you using Derek?
I'm using Windows XP too.
I stand by my assertion that memory released by reducing the size a sequence is made available for reuse. If the amount of memory released is larger than the system page size, that memory can be reused by other applications.
I'm using two measurements to confirm this. Using the Windows system monitor, I'm looking at the Available Physical Memory (APM) and the "Mem Usage" (MU) for the eui.exe process.
As memory is allocated and assigned to the 'x' object, APM is decreasing and MU is increasing. When the 'x' object is assigned 0, APM is increases to (almost) the initial value, and MU decreases to (almost) its initial value. The residual amount I think is associated with the minimum allocation size for RAM (usually 4K or system page size).
Also, the time difference between concatenating and pre-allocating is negliable.
Here is my pre-allocation version
clear_screen() integer c object ch object x sequence t atom e c = 1 puts(1, "Begin?\n") ch = gets(0) t = repeat(0,1000) x = repeat(0, 50*500) puts(1, "Pre-allocation done\n") ch = gets(0) puts(1, "Allocating ...\n") e = time() for i = 1 to 50 do -- adjust if it grabs too much memory for your system ? i for j = 1 to 500 do for q = 1 to 1000 do t[q] = rand(1000) / rand(1000) end for x[c] = t c += 1 end for end for ? time() - e puts(1, "End of allocation\n") ch = gets(0) x = 0 puts(1, "X deferenced\n") ch = gets(0)
What about the Eu version? Are you using 4.03a or a more bleeding-edge version? Any super-recent changes to memory handling, garbage collection?
I don't think so.
Anyway, not only did it not free the RAM, but it used way more of it too. With the same code as before (my code, with the loops), when the counter is at 50 I get: 878,522K used, 200,000K more than before! And it doesn't free it either. After setting x = 0 (or x = {}, no difference), it only goes down to 780,696, still 100K more than the 3.1 version used maximum.
What are you using to measure this? I'm not seeing this effect at all.
18. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 31, 2009
- 985 views
Anyway, not only did it not free the RAM, but it used way more of it too. With the same code as before (my code, with the loops), when the counter is at 50 I get: 878,522K used, 200,000K more than before! And it doesn't free it either. After setting x = 0 (or x = {}, no difference), it only goes down to 780,696, still 100K more than the 3.1 version used maximum.
What are you using to measure this? I'm not seeing this effect at all.
Task Manager process list, Mem Usage column for exw.exe (eui? what's that?). I also have a "free ram" meter in my taskbar that shows available RAM and I can see the effect there.
And just to prove it isn't available to other apps, I can...well, prove it. I have 2 gigs of ram. So going by my FreeRam tool it shows about 1.25 gigs are free before running the program. Running this program on v4 drops that to about 411MB free. Then when I supposedly release the memory, I get about 90 MB back, so it shows 500 MB free. So, if that's true, and I now run another instance of the program without closing the first one, it should quickly eat up all my available RAM and drive the system into the ground. But if you are right, it should be able to re-use the memory from the first process and everything will be fine.
But, running that second process does run the system into the ground. FreeRAM quickly drops to zero. Watching in the task manager, process1 holds its RAM absolutely steady at 780,000 or so. So process2 still needs plenty more and is struggling to get memory, and now you see all the other processes on the system start to drop their RAM usage, presumably as it is swapped out to the paging file so process2 can use it. So we can see process2 slowly gaining RAM at this point, and all the other processes dropping EXCEPT the Eu process1, which STILL is holding on to every byte! Diabolical!
19. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by DerekParnell (admin) Jul 31, 2009
- 995 views
(eui? what's that?)
This might be the cause of our different results.
eui.exe is the Version 4 Euphoria executable.
exw.exe is the version 3 Euphoria executable.
20. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by jimcbrown (admin) Jul 31, 2009
- 1081 views
(eui? what's that?)
This might be the cause of our different results.
eui.exe is the Version 4 Euphoria executable.
exw.exe is the version 3 Euphoria executable.
The change to eui.exe occurred after 4.0a3
I am curious, when you run the interpreter by itself, does it say it is using managed memory or system memory?
21. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by mattlewis (admin) Jul 31, 2009
- 1045 views
x = <big sequence> y = x x = 0 -- y still references big sequence, so memory is not released
But are there situations where I set all explicit references to atoms and there would still be an internal reference hanging around?
It might be possible. If there was a temporary variable used at top level that referenced the sequence, it might not be released. v4 has changed a lot of things about the way references are handled.
One change is that we're trying to release references created by temps as soon as possible. Previously, they were often only released at the end of their routine, which was basically never, if the routine was actually the top level.
Matt
22. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by DerekParnell (admin) Jul 31, 2009
- 1061 views
The change to eui.exe occurred after 4.0a3
Did it? Hmmm it has been awhile between releases. Hopefully we'll have a beta release out soon.
I am curious, when you run the interpreter by itself, does it say it is using managed memory or system memory?
Ahh... I compile Euphoria using the System Memory option.
My config.wat file is ...
# Configuration for Watcom MANAGED_MEM=0 EUPHORIA=1 DELTREE=del /Q /S RM=del /Q RMDIR=rmdir /Q/S TRUNKDIR=C:\Projects\eu_proj\eu40\trunk BUILDDIR=C:\Projects\eu_proj\eu40\trunk\source
I'll rebuild using managed mem to see if it does anything different.
23. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by DerekParnell (admin) Jul 31, 2009
- 1007 views
I'll rebuild using managed mem to see if it does anything different.
Yep, using mananged_mem exhibits the effects that Andy reported. One needs to compile with System Memory in order for it to release memory.
24. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by mattlewis (admin) Jul 31, 2009
- 1037 views
I'll rebuild using managed mem to see if it does anything different.
Yep, using mananged_mem exhibits the effects that Andy reported. One needs to compile with System Memory in order for it to release memory.
That makes sense. They both use the windows allocation API, but the 'managed memory', which is the default, caches your freed memory for its later reuse. This is what euphoria has always done (for quite a long time, at least). This speeds up the case where there is a lot of allocation and deallocation (though not nearly as much as it used to on older windows).
Perhaps we should look into limiting the size, and after some amount, we let the memory go back to the operating system. I'm not sure how difficult it would be, but it seems like the right thing to do.
Matt
25. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 31, 2009
- 1015 views
- Last edited Feb 03, 2011
The change to eui.exe occurred after 4.0a3
I am curious, when you run the interpreter by itself, does it say it is using managed memory or system memory?
Yeah, says managed memory. I didn't even notice that.
So, the question is -- if that's the way it is gonna be, is there any reason I couldn't use a "system memory" version? Does it mess up the way it interacts with .dlls or anything?
26. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by jimcbrown (admin) Jul 31, 2009
- 1033 views
The change to eui.exe occurred after 4.0a3
I am curious, when you run the interpreter by itself, does it say it is using managed memory or system memory?
Yeah, says managed memory. I didn't even notice that.
So, the question is if that's the way it is gonna be, is there any reason I couldn't use a "system memory" version? Does it mess up the way it interacts with .dlls or anything?
The releases default to managed memory because system memory doesn't work on Windows 9x, while managed memory works on all 32bit Windows variants, and it was simpler than releasing seperate 9x and NT versions.
27. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 31, 2009
- 1034 views
- Last edited Feb 03, 2011
I'll rebuild using managed mem to see if it does anything different.
Yep, using mananged_mem exhibits the effects that Andy reported. One needs to compile with System Memory in order for it to release memory.
That makes sense. They both use the windows allocation API, but the 'managed memory', which is the default, caches your freed memory for its later reuse. This is what euphoria has always done (for quite a long time, at least). This speeds up the case where there is a lot of allocation and deallocation (though not nearly as much as it used to on older windows).
Perhaps we should look into limiting the size, and after some amount, we let the memory go back to the operating system. I'm not sure how difficult it would be, but it seems like the right thing to do.
Well, if there was a change, it must have been at v3.0, because that is when I started having this problem. Like I said, I reported on this a couple of times over a year ago. Looking at the code in be_alloc.c, which I do not understand, I can nevertheless tell that the code for Windows is much more complex than for other platforms. Any chance there is actually a subtle bug in there -- an unintended change? Why, for instance, in my example when I set x = {} immediately get back 90MB? What's special about 90MB? Is it releasing one block of something and then stopping when it shouldn't?
If there is no bug, would a simple programmatic option be possible that could control that amount of caching? (e. "with cache <min/normal/large>") Which would not affect the ability to use all the memory you need, but would allow (with option "min") to release as much as possible (at the expense of alloc/dealloc speed if that's the cost) when finished in order to keep the memory usage of a process no bigger than need be for what is it currently doing? (Option normal could be normal/default and large could actually pre-allocate extra memory to keep things speedy. Or some such scheme. Possible? Smart?) Or maybe an explicit command that could be put anywhere? (e.g. "free_cache()")
Or does it actually need to be compiled differently?
It doesn't come up that often, but when it does it turns your program into a real resource hog, even when it is finished with the resources. I know Euphoria has always prided itself on automatic garbage collection, but it is holding on to the trash.
28. Re: Memory usage on Win32: Euphoria usage vs. what Task Manager displays
- Posted by AndySerpa Jul 31, 2009
- 1063 views
Oh yeah, and what is the reason that v4 used so much more memory in total vs v3.1? In my example, it used 200,000K more on the same code...