xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 9, 2018 11:37:01 GMT -5
I was trying to add 19 multiline tooltips [ about 29k] I read in a tip then add the tip, but after 16 tips I get file errors , and some other program indicators stop working. I suspect I short of allocated memory ??
|
|
|
Post by Chris Iverson on Apr 9, 2018 11:43:29 GMT -5
Do you have any code you can post that demonstrates this?
I'm afraid I don't have anything to do with 29k tooltips, myself.
|
|
|
Post by Brandon Parker on Apr 10, 2018 7:34:07 GMT -5
Check out this code; you should be able to learn how to use it and stick it in your code where you are having problems to see if your program continuously consumes memory.
Open "psapi.dll" For DLL As #psapi
'Create the Struct for watching memory usage
Struct ProcessMemoryCounters, cb As ulong,_ PageFaultCount As ulong,_ PeakWorkingSetSize As ulong,_ WorkingSetSize As ulong,_ QuotaPeakPagedPoolUsage As ulong,_ QuotaPagedPoolUsage As ulong,_ QuotaPeakNonPagedPoolUsage As ulong,_ QuotaNonPagedPoolUsage As ulong,_ PagefileUsage As ulong,_ PeakPagefileUsage As ulong
Struct MemData, MyMemoryUsage As Double
MemData.MyMemoryUsage.struct = Val(ConvertToDouble$(0, 1, 1))
Print "Using ";GetUsedMemory(ErrorMsg$);" MB of Memory."
Close #psapi End
'__________________________________________________________________________________________________________________________________ '__________________________________________________________________________________________________________________________________ Function GetUsedMemory(ByRef ErrorMsg$) 'returns the memory used by the current process ' 'returns -1 if an error is encountered ' the error message is stored in the submitted variable ErrorMsg$ = "" ProcessMemoryCounters.cb.struct = len(ProcessMemoryCounters.struct) CallDLL #kernel32, "GetCurrentProcess", hProcess As ulong cb = len(ProcessMemoryCounters.struct) CallDLL #psapi, "GetProcessMemoryInfo", hProcess As ulong,_ ProcessMemoryCounters As struct,_ cb As ulong,_ result As long If result Then GetUsedMemory = (ProcessMemoryCounters.PagefileUsage.struct/1024/1024) MemData.MyMemoryUsage.struct = Val(ConvertToDouble$(GetUsedMemory, 3, 4)) Else ErrorMsg$ = GetLastError$(ErrorMsg$) GetUsedMemory = -1 End If End Function
'__________________________________________________________________________________________________________________________________ '__________________________________________________________________________________________________________________________________
Function GetLastError$(Message$) dwMessageID = GetLastError() dwFlags = _FORMAT_MESSAGE_FROM_SYSTEM nSize = 1024 lpBuffer$ = Space$(nSize) + chr$(0) CallDLL #kernel32, "FormatMessageA", dwFlags As ulong, _ lpSource As ulong, _ dwMessageID As ulong, _ dwLanguageID As ulong, _ lpBuffer$ As ptr, _ nSize As ulong, _ Arguments As ulong, _ result As ulong GetLastError$ = Left$(lpBuffer$, result) End Function
'__________________________________________________________________________________________________________________________________ '__________________________________________________________________________________________________________________________________
Function GetLastError() CallDLL #kernel32, "GetLastError", GetLastError As ulong End Function
'__________________________________________________________________________________________________________________________________ '__________________________________________________________________________________________________________________________________
Function ConvertToDouble$(value, sigDig, decDig) sigDig$ = string$("#", sigDig) decDig$ = string$("#", decDig) ConvertToDouble$ = Using(sigDig$;".";decDig$, value) End Function
'__________________________________________________________________________________________________________________________________ '__________________________________________________________________________________________________________________________________
Function string$(myString$, numstring) For i = 1 To numstring string$ = string$ + myString$ Next i End Function
'__________________________________________________________________________________________________________________________________ '__________________________________________________________________________________________________________________________________
{:0)
Brandon Parker
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 12, 2018 12:27:25 GMT -5
I implemented the code, I made the "Open "psapi.dll" For DLL As "psapi" part as a sub, and changed the print to a print to window. Within the program if I initiate approx every 30 seconds GOSUB [MEMCHK] the memory usage INCREASES with each GOSUB [MEMCHK] I assume the "psapi.dll" code is not being released after close, and therefor slowly eating memory...
If I use A button Click to initiate GOSUB [MEMCHK] memory usage is stable.
Why the difference?
|
|
|
Post by Chris Iverson on Apr 12, 2018 12:45:56 GMT -5
How are you ending the GOSUB?
Do you just end it with a wait, or do you do a RETURN?
And for that matter, how are you triggering the GOSUB every 30 seconds?
|
|
|
Post by Brandon Parker on Apr 12, 2018 14:32:50 GMT -5
How long are you allowing the program to run for? Garbage collection is not always immediate and where I implemented this I can say that memory usage goes up/ down in a sawtooth pattern. What you do not want to see is that the sawtooth pattern continues to increase overall over time.
I'm running the code using a timer at the moment and it's been running for about 10 minutes with only a sawtooth pattern visible and LB's Commit size it not increasing so there's no memory leak in the memory checking code. That being said, this is what it is meant for; to help you determine if you have a memory leak somewhere in your code.
{:0)
Brandon Parker
|
|
|
Post by Rod on Apr 12, 2018 14:48:25 GMT -5
You are much more likely to be running out of memory by drawing inappropriately and not managing segments, tooltips are trivia unless you are adding multiple endless tooltips. So give us more of an overview of your code for specific advice.
|
|
|
Post by Brandon Parker on Apr 12, 2018 15:21:18 GMT -5
XTAL, Did this memory leak just start or was it present prior to the incorporation of ToolTips?
{:0)
Brandon Parker
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 12, 2018 16:30:31 GMT -5
As far as I can tell I have not had an leaks even adding ToolTips, but then I had no way to check... It only occurs if I GOSUB {MEMCHK} every 30 seconds thru my timing loop when I post time message I see a used memory gain.... Just discovered if I open commport and let pgm start , even the Button click GOSUB MEMCHK gains..
click 1- 15.625 Meg click 2- 15.685 Meg click 3- 15.750 Meg click 4- 15.828 Meg
The compiler seems to remember, that why it got to 15+ multiple program runs....
I will disable tootip generation to see what happens
no tool tips an comm port close , I didn't see much change
no tool tips and com port OPEN and program compiled....seems to be growing all thats going on Tx "?" to GRBL and Receive different length status info........
9:57:39-1776 <27.874sec> <15msTIC> <Mem=7.1523MB delta<7.1523MB>
19:58:07-1776 <27.872sec> <15msTIC> <Mem=7.3085MB delta<0.1562MB>
19:58:35-1776 <27.771sec> <15msTIC> <Mem=7.371MB delta<0.0625MB>
19:59:03-1776 <27.868sec> <15msTIC> <Mem=7.4453MB delta<0.0742MB>
19:59:31-1776 <27.828sec> <15msTIC> <Mem=7.5078MB delta<0.0625MB>
19:59:59-1776 <27.786sec> <15msTIC> <Mem=7.539MB delta<0.0312MB>
20:00:26-1776 <27.839sec> <15msTIC> <Mem=7.6289MB delta<0.0898MB>
20:00:54-1776 <27.835sec> <15msTIC> <Mem=7.6914MB delta<0.0625MB>
20:01:22-1776 <27.759sec> <15msTIC> <Mem=7.7539MB delta<0.0625MB>
20:01:50-1776 <27.83sec> <15msTIC> <Mem=7.8164MB delta<0.0625MB>
20:02:18-1776 <27.809sec> <15msTIC> <Mem=7.8515MB delta<0.0351MB>
20:02:46-1776 <28.017sec> <15msTIC> <Mem=7.9179MB delta<0.0664MB>
20:03:14-1776 <27.862sec> <15msTIC> <Mem=7.9101MB delta<-0.0078MB>
20:03:41-1776 <27.796sec> <15msTIC> <Mem=7.9414MB delta<0.0312MB>
20:04:09-1776 <27.799sec> <15msTIC> <Mem=8.0039MB delta<0.0625MB>
20:04:37-1776 <27.873sec> <15msTIC> <Mem=8.0664MB delta<0.0625MB>
|
|
|
Post by Rod on Apr 13, 2018 1:40:50 GMT -5
There is an assumption that this is a memory issue. Running out of memory creates a range of very specific error codes. On the other hand processing an endless loop cause freezing and none response. If your processing cycle takes 156 ms to complete and you call it ever 16ms your going to have problems.
So does the program stop with an error code or does it just freeze up. If it stops what are the exact error messages, if it is a memory issue the message will changed, if it is a process error it will be the same each time.
So what kind of stop do we have?
edit to add at 15mb you are not going to hit memory problems, but if you have thousands of drawing actions queued then the system appears to freeze as these are auctioned. Scan is your friend here. You might also be stuck looking at the com port for input that never arrives. Do you stop processing while the tooltips are on display? Or does it keep running? We need an overview of what your program is doing. You might also get Liberty BASIC Pro, it has a code profiler that shows you what time is spent where. But you can time blocks of code to get a handle on timing flow.
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 14, 2018 8:49:47 GMT -5
I've fallen back to previous version - no tool tips With comm Closed I'm I'm stable 4-5 minute then gain . With Comm open I constantly gain ....so will try to find out why......
-----COMM PORT CLOSED ------ 09:25:02--1776 <27.765sec> <15.6msTIC> < Mem-8.957031MB> < 8.957031MB> 09:25:30--1776 <27.75sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:25:58--1776 <27.753sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:26:25--1776 <27.779sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:26:53--1776 <27.751sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:27:21--1776 <27.751sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:27:49--1776 <27.763sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:28:16--1776 <27.754sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:28:44--1776 <27.761sec> <15.6msTIC> < Mem-8.957031MB> < 0MB> 09:29:06--1776 <21.54sec> <12.1msTIC> < Mem-8.957031MB> < 0MB> 09:29:33--1776 <27.771sec> <15.6msTIC> < Mem-8.988281MB> < 0.03125MB> 09:30:01--1776 <27.751sec> <15.6msTIC> < Mem-8.988281MB> < 0MB> 09:30:29--1776 <27.781sec> <15.6msTIC> < Mem-8.988281MB> < 0MB> 09:30:57--1776 <27.76sec> <15.6msTIC> < Mem-8.988281MB> < 0MB> 09:31:24--1776 <27.784sec> <15.6msTIC> < Mem-8.988281MB> < 0MB> 09:31:52--1776 <27.75sec> <15.6msTIC> < Mem-8.988281MB> < 0MB> 09:32:20--1776 <27.769sec> <15.6msTIC> < Mem-8.988281MB> < 0MB> 09:32:48--1776 <27.75sec> <15.6msTIC> < Mem-8.851562MB> < -0.136718MB> 09:33:16--1776 <27.75sec> <15.6msTIC> < Mem-8.851562MB> < 0MB> 09:33:43--1776 <27.744sec> <15.6msTIC> < Mem-8.851562MB> < 0MB> 09:34:11--1776 <27.765sec> <15.6msTIC> < Mem-8.851562MB> < 0MB> 09:34:39--1776 <27.771sec> <15.6msTIC> < Mem-8.851562MB> < 0MB> 09:35:08--1776 <28.887sec> <16.2msTIC> < Mem-8.851562MB> < 0MB> 09:35:35--1776 <26.844sec> <15.1msTIC> < Mem-8.871093MB> < 0.019531MB> 09:36:02--1776 <27.801sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:36:30--1776 <27.752sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:36:58--1776 <27.781sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:37:26--1776 <27.791sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:37:53--1776 <27.748sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:38:21--1776 <27.771sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:38:49--1776 <27.752sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:39:17--1776 <27.855sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:39:45--1776 <27.875sec> <15.6msTIC> < Mem-8.871093MB> < 0MB> 09:40:13--1776 <27.893sec> <15.7msTIC> < Mem-8.871093MB> < 0MB> 09:40:41--1776 <27.964sec> <15.7msTIC> < Mem-8.867187MB> < -0.003906MB> 09:41:08--1776 <27.787sec> <15.6msTIC> < Mem-8.867187MB> < 0MB> ------COMM PORT OPEN -------- 09:43:27--1776 <27.785sec> <15.6msTIC> < Mem-8.277343MB> < -0.523437MB> 09:43:55--1776 <27.918sec> <15.7msTIC> < Mem-8.339843MB> < 0.0625MB> 09:44:23--1776 <27.836sec> <15.6msTIC> < Mem-8.402343MB> < 0.0625MB> 09:44:51--1776 <27.854sec> <15.6msTIC> < Mem-8.433593MB> < 0.03125MB> 09:45:19--1776 <27.864sec> <15.6msTIC> < Mem-8.527343MB> < 0.09375MB> 09:45:47--1776 <27.935sec> <15.7msTIC> < Mem-8.558593MB> < 0.03125MB> 09:46:15--1776 <27.92sec> <15.7msTIC> < Mem-8.621093MB> < 0.0625MB> 09:46:42--1776 <27.84sec> <15.6msTIC> < Mem-8.664062MB> < 0.042968MB> 09:47:10--1776 <27.941sec> <15.7msTIC> < Mem-8.695312MB> < 0.03125MB>
|
|
|
Post by Rod on Apr 14, 2018 10:05:28 GMT -5
I don't see any gains, this is normal, this is how garbage collection works. When Windows gets round to it unused/released memory is returned to the pool. I ask again, how does the program fail? What is wrong from the users perspective? Does it stop responding? Does it slow right down?
8mb of memory use is trivial, you don't have a memory problem, so we need to better understand what the problem is.
|
|
|
Post by Carl Gundel on Apr 14, 2018 13:48:59 GMT -5
As was alluded to above, it is important that each GOSUB to a subroutine ends up with a RETURN. Otherwise you will consume more and more memory that will never get reclaimed.
Good:
...some code... gosub [subA] ...some code...
[subA] ...some code... return
Bad:
...some code... gosub [subA] ...some code...
[subA] ...some code... goto [someplace] Or another bad:
...some code... gosub [subA] ...some code...
[subA] ...some code... wait -Carl
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 14, 2018 17:30:16 GMT -5
It's an abnormal gain. I left it running overnight with comm port open . Started with about 9MB program was froze this am with 69MB.... I'm trying to determine what portion of timing loop has issue, but so far no success. I made a small NON WINDOWED pgm with similiar Timming and I think it is OK...I see gain and loss.
------------ CommPort Now Open --------------------- Tx "?" to Arduino{with GRBL 1.1F} then rcv status <18:16:56 -- 1776> Mem-8.203125MB> < 8.203125MB>--ALARM-->Tx reset <1> WIN$= <ALARM|MPOS:0.0000,0.0000,0.0000|FS:0,0> <0> win$= [MSG:Caution: Unlocked] <0> win$= ok <0> win$= ok <18:17:23 -- 1776> Mem-8.203125MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:17:51 -- 1776> Mem-8.203125MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:18:19 -- 1776> Mem-8.203125MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:18:47 -- 1776> Mem-8.203125MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:19:14 -- 1776> Mem-7.988281MB> < -0.214843MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:19:42 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:20:10 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0|WCO:-232.0003,-190.0020,-28.0003> <18:20:38 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0|OV:100,100,100> <18:21:05 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:21:33 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:22:01 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:22:29 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:22:57 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:23:24 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:23:52 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:24:20 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0> <18:24:47 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0|WCO:-232.0003,-190.0020,-28.0003> <18:25:15 -- 1776> Mem-7.988281MB> < 0MB> <1> WIN$= <IDLE|MPOS:0.0000,0.0000,0.0000|FS:0,0|OV:100,100,100> <18:25:43 -- 1776> Mem-7.988281MB> < 0MB>
|
|
|
Post by Rod on Apr 15, 2018 2:52:41 GMT -5
Did it write anything to the error log? That will give us the best chance of finding out what is going on. But I can guess that you are drawing or printing something without managing the memory it is using or creating an ever growing variable. How large is the program? Share it as an attachment here, we can delete it once fixed.
|
|